显示创建的线程:

#include <pthread.h>
#include <stdio.h>
void *fn(void *arg)
{
    return ((void *)0);
}
int main()
{
    int i=0;
    pthread_t thread;
    while(1){
        if(pthread_create(&thread,NULL,fn,NULL)!=0)
            return;
        i++;
        printf("i=%d\n",i);
    }
}

----

:$gcc demo.c -o demo.out -lpthread

-------------------------------------------------------------------

在ubuntu中装了个eclipse作为ide工具,但编译上面的代码默认是通不过的。原因是不能自动识别出pthread库(尽快我们加了include语句)。如果还回来用gcc手工加参数,那用eclipse还有啥意义。所以这样解决——Project Properties、c/c++ build、settings、Libraries 中加入pthread 就好了。