passing unsafe pointers via channels
Posted: Mon Oct 28, 2019 11:43 pm
I'm testing the performance of having multiple threads working together at the same time. so what i'm trying to do is, creating one thread that will distribute blocks of data (16B each block) to multiple threads. each thread will encrypt the whole block of data, and it will keep receiving more blocks until there's no more unencrypted blocks of data. the whole data is represented as a matrix of 10*16, so we have 10 blocks of data, each one has 16B. I tried to pass one row of the matrix (one block of data) via the channel to another thread to test my idea, but I got this error:
my code:xrun: Program received signal ET_ILLEGAL_RESOURCE, Resource exception.
main_task_1 (frame=0x7fe7c) at ../src/test.xc:98
98 c[0]:> *data;
Code: Select all
int main(void){
uint8_t data [160];
int counter =0;
for(int i=0; i<160; i++){
data[i]=i;
}
uint8_t mat[10][16];
for(int i=0 ; i<10 ; i++){
for(int j=0 ; j<16 ; j++){
mat[i][j]=data[16*i+j];
}
}
chan c[7];
par{
unsafe{//thread0
for(int i=0; i<10 ; i++){//will loop 10 times since we have 10 blocks of data
//uint8_t* unsafe p=mat[i]; //pointer to a single block of data
c[counter]<:(uint8_t* unsafe) &mat[i];//passing a single block of data as a reference through the channel
counter=(counter+1)%7;//we have 7 threads for encryption, but we'r using one just to test
}//finish of loop
}//finish thread0
unsafe{//thread1
uint8_t data[16];
c[0]:> *data;//one block of data should be placed in this array
for(int i=0; i <16; i++)
printf("%d \n", data[i]);//just to make sure that the whole block of data is transferred successfully
}//finish thread1
}