Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <pthread.h>
- #include <stdio.h>
- #include <stdlib.h>
- pthread_mutex_t mymutex;
- pthread_cond_t mycond;
- int somevalue = 0;
- void some_func()
- {
- printf("fck yeaa\n");
- }
- void *onethread()
- {
- pthread_mutex_lock(&mymutex);
- while(somevalue == 0) pthread_cond_wait(&mycond, &mymutex);
- if(somevalue == 0xdeadbeef)
- some_func();
- pthread_mutex_unlock(&mymutex);
- }
- void *otherthread()
- {
- pthread_mutex_lock(&mymutex);
- somevalue = 0xdeadbeef;
- pthread_cond_broadcast(&mycond);
- pthread_mutex_unlock(&mymutex);
- }
- int main()
- {
- pthread_t p1;
- pthread_t p2;
- pthread_cond_init (&mycond, NULL);
- pthread_mutex_init(&mymutex, NULL);
- pthread_create(&p1, NULL, onethread, (void *) 0);
- pthread_create(&p2, NULL, otherthread, (void *) 0);
- pthread_exit(NULL);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement