- 论坛徽章:
- 0
|
SARS:为什么Unix中pthread_create创建不了线程?
include <stdio.h>;
#include <stdlib.h>;
#include <sys/errno.h>;
#include <pthread.h>;
#include <unistd.h>;
extern "C" void * Thread_handler(void *);
int main(void)
{
pthread_t thread1 = 0 ;
int RetCode;
RetCode=pthread_create(&thread1, NULL,Thread_handler, NULL);
printf("RetCode=%d, tid=%d\n",RetCode,thread1);
sleep(2);
exit(0);
}
void * Thread_handler(void * arg)
{
printf("Hello kid!\n"
return NULL;
}
编译时要加-mt -lpthread
CC -g -o 3 3.cpp -mt -lpthread |
|