hi!
I have a program, and I have 2 threads.
in the first I lock a semaphore, and in the second I have to run some code, but only after the first locked the semaphore.
right now I do it with busy-waiting:
void *thread_proxy_stub(void *arg)
{
int x;
// wait untill the main thread will lock the first semaphore:
while (1)
{
x = semctl ( sem1 , 0 , GETNCNT); // get the number of waiting threads.
if (x == -1) exit(-1); // error - exit.
if (x > 0) break; // if the main thread locked the first semaphore - break the loop.
usleep(1); // else - wait milisecond and check again.
}
// continue for the code...
Is there any other way to do it?
I need an answer today, so if someone could help me, please do it...
Thanks,
-Nate