作者:時節 | 来源:互联网 | 2024-10-12 14:20
#include
#include
#define NUM_THREAD 5
void *print_hello(void *threadid)
{
long tid;
tid = (long)threadid;
printf("Hello world! thread#%ld\n", tid);
pthread_exit(NULL);
}
int main()
{
pthread_t threads[NUM_THREAD];
int rc;
long i;
for(i =0; i
输出:
In main: create thread 0
In main: create thread 1
In main: create thread 2
In main: create thread 3
In main: create thread 4
Hello world! thread#4
Hello world! thread#3
Hello world! thread#2
Hello world! thread#1
Hello world! thread#0