createthread.c

来自「LINUX C编程实战这本书附带光盘的原代码」· C语言 代码 · 共 26 行

C
26
字号
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>

int * thread(void * arg)
{
	pthread_t newthid;

	newthid = pthread_self();
	printf("this is a new thread, thread ID = %d\n", newthid);
	return NULL;
}

int main(void)
{
	pthread_t thid;

	printf("main thread ,ID is %d\n",pthread_self());
	if(pthread_create(&thid, NULL, (void *)thread, NULL) != 0) {
		printf("thread creation failed\n");
		exit(1);
	}
	exit(0);
}

⌨️ 快捷键说明

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