I'm building a multithread applications.
My threads have to execute an instruction block only if a pointer becomes !=nil
void *fun(struct coordinates *app){
struct coordinates coord;
coord.x = app->x;
coord.y = app->y;
//printf("\n %p %d %d", t_queue[coord.x][coord.y], coord.x, coord.y);
while(1){
if(t_queue[coord.x][coord.y]){
pthread_mutex_lock(&Thread_Mutex);
/*
critical zone
*/
pthread_mutex_unlock(&Thread_Mutex);
}
//sleep(1);
}
pthread_exit(nil);
}
Instead of the if (t_queue[coord.x][coord.y])
, I'd like to use another function that really waits and does not use so much cpu (else my cpu go to 100%, only using sleep it will go down to 10% only checking if the variable become !=
to nil
)