Chanend in select causing exception

If you have a simple question and just want an answer.
babazaroni
Experienced Member
Posts: 94
Joined: Sun Feb 10, 2013 4:47 am

Chanend in select causing exception

Post by babazaroni »

I'm getting a resource violation in the simple program below.  When task2 sends over the channel to task1, a resource violation happens in the select statement of task1.

Any ideas?

 

#include <xs1.h>

void task1(chanend c){

    select{
        case c :> int val:  // resource violation happens here when task2 sends over chan c
            val++;
        break;
    }
}

void task2(chanend c){
    timer t;
    int time;

    t :> time;
    time += 1E8;

    t when timerafter(time) :> int _;

    outuint(c,0);
}


int main()
{
    chan c;
    par{
        task1(c);
        task2(c);
    }
    return 0;
}
 



User avatar
sethu_jangala
XCore Expert
Posts: 589
Joined: Wed Feb 29, 2012 10:03 am

Post by sethu_jangala »

The reason you are getting the error is because, you are sending unsigned int value in task 2 over a channel and you are reading an int value in task 1 from channel c. You need to specify the data type consistently on both the channel ends.