编译的的时候需要加-lpthread选项,因为它不是linux默认的库。
#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<pthread.h>
#include<string.h>
void * thread_function(void * arg);
char message[] = "Hello world!";
int main(){
int res;
pthread_t a_thread;
void * thread_result;
res = pthread_create(&a_thread, NULL, thread_function, (void *)message);
if( res != 0 ){
perror("Thread create failed");
exit(1);
}
printf("Waiting for thread to finish...\n");
res = pthread_join(a_thread,&thread_result);
if( res != 0 ){
perror("Thread join failed");
exit(1);
}
printf("Thread joined, it reaturned %s\n",(char *)thread_result);
printf("Message is now %s\n", message);
exit(0);
}
void * thread_function(void *arg){
printf("thread function is running, Argument was %s\n",(char *)arg);
sleep(3);
strcpy(message,"Bye!");
pthread_exit("Thanks for cpu time");
}
分享到:
相关推荐
把解压库文件中的Pre-built.2文件夹中的lib,include文件复制,黏贴到c盘:...最后把Pre-built.2文件夹中的lib中的pthreadVSE2.dll pthreadVC2.dll复制黏贴到C:\Windows\SysWOW64中去就可以在vb6.0启动pthread文件了
pthread.lib文件下载,本人用于crf++安装时使用。。 pthread.lib文件下载,本人用于crf++安装时使用。。 pthread.lib文件下载,本人用于crf++安装时使用。。 pthread.lib文件下载,本人用于crf++安装时使用。。
pthread, window pthread
pthread_testcancel pthread_kill pthread_cancel 的使用例子
PThread header file
以下是对pthread_cond_wait的用法进行了详细的分析介绍,需要的朋友可以过来参考下
VC环境下pthread.h无效的解决办法
pthread资源包,pthread源码和已经编译好的VS2019_x64版本 #include <pthread.h> pthread_t newThread; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setscope(&attr, PTHREAD_SCOPE_PROCESS); ...
pthread静态库,动态库,vs2019,win32/x64 ,debug/release
在windows下对pthread源码进行编译,pthread是一套跨平台线程库,用它编写多线程可以统一平台调用方式
VS编译时无法打开 源 文件 "pthread.h"。是因为微软VS没有pthread.h. 项目--属性--配置属性--c/c++常规--附加包含目录添加pthread.h所在的文件夹。
高斯消元法的并行实现,vs2015,pthread。同时结合了SSE和AVX,AVX X64下运行。
Linux 静态编译时使用的libc和pthread库
java、win32、pthread三种线程库均有 适合用来学习多线程操作的入门例程
pthread官方发布的有windows版本的预编译库,但那是动态库,不习惯,编译好一个文件,还要复制一大堆东西进去程序才能运行,麻烦。于是下源码自己编译了一个静态库,方便自己,也方便大家使用。内有详细的编译方法,...
pthread使用手册
主要是pthread API组成的一个简单的例子,更关键的是能够熟悉pthread_join,他能够一直阻塞整个进程直到他等待的那个线程结束才能继续执行他后面的代码。 编译使用gcc pthread.c -o pthread -pthread
里面包含pthread.h pthread.lib pthread.dll
东南大学 操作系统实验2 用pthread实现矩阵相乘 含代码及报告
多线程编程指南,SUN的Pthread线程库手册,中文版的。