||
如下所示代码在主线程中新建一个子线程,用到了pthread函数库中的pthread_create函数。
/*pthread*/
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
void *newThread(void *argv)
{
Printf(“this is in the new thread! \n”);
}
Int main(void)
{
Pthread_t threaded;
Pthread_create(&threaded, NULL, newThread, NULL);
Printf(“this is in the old thread! \n”);
Sleep(1);
Return0;
}
编译指令如下所示,第一次编译时未用-l选项指定要链接的函数库,导致gcc找不到pthread_create函数而提示错误;第二次编译时虽然加上了-l选项,但因为函数库名错误而提示找不到函数库;第三次编译时,指定pthread函数库后终于编译通过了。
Gcc pthread.c
Gcc pthread.c –l thread
Gcc pthread.c –l pthread
Archiver|手机版|小黑屋|52RD我爱研发网 ( 沪ICP备2022007804号-2 )
GMT+8, 2024-11-24 10:39 , Processed in 0.029514 second(s), 18 queries , Gzip On.
Powered by Discuz! X3.5
© 2001-2023 Discuz! Team.