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

📄 hellothread.c

📁 linux下线程编程序事例,已经验证过了,很好用
💻 C
字号:
#include <pthread.h>#include <stdio.h>//#define NULL 0int  i = 0;void *threadA(void *arc){//	int i = 0;        while(1)        {                printf("hello threadA***%d***times\n", i++);          //      printf("hello threadA***%d***times\n",*(int *)arc);                sleep(2);         }}                                                                void *threadB(void *arc){    //  int i = 0;        while(1)        {                printf("hello threadB***%d***times\n", i++);        //        printf("hello threadB***%d***times\n",*(int *)arc);                sleep(2);        }}int  main(){        pthread_t threadidA, threadidB;	int arcA = 123;	int arcB = 456;        pthread_attr_t attr;   	pthread_attr_init(&attr);        pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);	pthread_create(&threadidA, &attr, &threadA,(int *) &arcA);        pthread_create(&threadidB, &attr, &threadB, (int *)&arcB);       // pthread_create(NULL, NULL, NULL, NULL);        pthread_join(threadidA, NULL);        pthread_join(threadidB, NULL);	while(1)        {                sleep(2);                printf("main test\n");        }        return 0;}

⌨️ 快捷键说明

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