Like vwait of tcl, is there anything in C programming?
Is there any way to wait for code until some variable is reset or changed
in C programming like vwait in tcl?
Sample code where we can implement the same:
Here using thread, we can set the variable getout to 1 and can proceed
further. Note: Due to some issues in code, i cannot use infinite while
loop for keep on checking the variable. Is there some kind of trigger for
the same task? Thanks in advance.
#include <stdio.h>
#include <pthread.h>
int getout = 0;
void *threadfunc(void *parm)
{
int x = 0;
for (;;) {
x++;
if (x == 500000) {
getout = 1;
}
}
return NULL;
}
void main () {
pthread_t pth;
pthread_create(&pth,NULL,threadfunc,"foo");
// wait for getout to be set to 1;
pthread_cancel(pth); // cancel the thread after wait
}
No comments:
Post a Comment