⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sem.c

📁 linux下的多线程调试工具
💻 C
字号:
#define _XOPEN_SOURCE 600#include <pthread.h>#include <semaphore.h>#include <stdio.h>#include <time.h>#include <fcntl.h>#include "alias.h"struct timespec wait = {0, 30000000};struct timespec rem;#define WAIT nanosleep (&wait, &rem)sem_t sem;FILE *fd;void *func () {    new_thread_alias (fd, "func");    sem_trywait (&sem);    sem_wait (&sem);    sem_post (&sem);    sem_trywait (&sem);}int main () {    pthread_t thread;    fd = alias_init ("alias");    new_thread_alias (fd, "main");    new_object_alias (fd, &sem, "sem");    sem_init (&sem, 0, 0);    pthread_create (&thread, NULL, func, NULL);    WAIT;    sem_post (&sem);    pthread_join (thread, NULL);    sem_destroy (&sem);    return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -