2.compile時,加入-pthread參數
範例=========================
#include <stdio.h>
#include <stdlib.h> //因為在fc系統下,exit會有warnning,include此就不會有了
#include <pthread.h> //unix下的多執行緒
void *mythread(void *arg)
{
for (;;) {
printf("thread\n");
sleep(1);
}
return NULL;
}
int main(void)
{
pthread_t th;
if (pthread_create(&th,NULL,mythread,NULL)!=0)
exit(0);
for (;;) {
printf("main process\n");
sleep(3);
}
}main process
thread
thread
thread
main process
thread
thread
thread
main process
thread
thread
thread
3 則留言:
請問 開頭的#include要inlcude甚麼
請問開頭要include甚麼 ??
嗯~ 修好了~
張貼留言