📄 cond.c
字号:
#define _XOPEN_SOURCE 600#include <pthread.h>#include <stdio.h>#include <time.h>#include "alias.h"struct timespec wait = {0, 10000000};struct timespec rem;#define WAIT nanosleep (&wait, &rem)pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;pthread_cond_t condition;FILE *fd;void *func () { new_thread_alias (fd, "func"); pthread_cond_wait (&condition, &mutex); pthread_cond_wait (&condition, &mutex);}int main () { pthread_t thread; pthread_condattr_t attr; fd = alias_init ("alias"); new_thread_alias (fd, "main"); new_object_alias (fd, &condition, "condition"); new_object_alias (fd, &mutex, "mutex"); pthread_cond_init (&condition, &attr); pthread_create (&thread, NULL, func, NULL); WAIT; pthread_cond_signal (&condition); WAIT; pthread_cond_broadcast (&condition); WAIT; pthread_cond_signal (&condition); pthread_cond_broadcast (&condition); pthread_join (thread, NULL); pthread_cond_destroy (&condition); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -