Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<pthread.h>
- pthread_cond_t cond;
- pthread_mutex_t mutex;
- void *thread_func1(void* arg){
- printf("thread1 started\n");
- printf("thread1: signalling\n");
- pthread_cond_signal(&cond);
- printf("thread1: signalled\n");
- printf("thread1: exiting\n");
- pthread_exit(0);
- }
- void *thread_func2(void* arg){
- printf("thread2 started\n");
- printf("thread2: waiting for signal..\n");
- pthread_cond_wait(&cond, &mutex);
- printf("thread2: signal received\n");
- printf("thread2: exiting\n");
- pthread_exit(0);
- }
- int main(int argc, char** argv){
- pthread_t thread1, thread2;
- pthread_create(&thread1, NULL, thread_func1, NULL);
- pthread_create(&thread2, NULL, thread_func2, NULL);
- pthread_join(thread1, 0);
- pthread_join(thread2, 0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment