📄 oncerun.c
字号:
#include <stdio.h>
#include <pthread.h>
pthread_once_t once = PTHREAD_ONCE_INIT;
void run(void)
{
printf("Fuction run is running in thread %d\n",pthread_self());
}
void * thread1(void *arg)
{
pthread_t thid=pthread_self();
printf("Current thread's ID is %d\n", thid);
pthread_once(&once,run);
printf("thread1 ends\n");
}
void * thread2(void *arg)
{
pthread_t thid=pthread_self();
printf("Current thread's ID is %d\n", thid);
pthread_once(&once, run);
printf("thread2 ends\n");
}
int main(void)
{
pthread_t thid1,thid2;
pthread_create(&thid1,NULL,thread1,NULL);
pthread_create(&thid2,NULL, thread2,NULL);
sleep(3);
printf("main thread exit! \n");
exit(0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -