`
yutiansky
  • 浏览: 193518 次
  • 性别: Icon_minigender_1
  • 来自: 本溪
社区版块
存档分类
最新评论

搭建环境 Eclipse + MinGW + pthread

阅读更多

1,安装Eclipse IDE for C/C++ Developers

  从『http://www.eclipse.org/downloads/』下载安装包。

  直接展开就可以啦。

 

2,安装MinGW

  2.1,从『http://sourceforge.net/projects/mingw/files/MinGW/』下载安装包。

    直接安装就可以啦。

 

  2.2,然后必须把MinGW/bin加到环境变量 PATH 中。

 

3,测试一下。

  把pthread-win32中的测试程序join0.c。

  #我稍微修改了一些。打印写信息。

#include "test.h"

void * func(void * arg) {
	printf("C : thread start!\n");
	Sleep(2000);
	printf("C : thread end!\n");
	pthread_exit(arg);
	/* Never reached. */
	exit(1);
}

int main(int argc, char * argv[]) {
	pthread_t id;
	int result;
	printf("M : create child thread!\n");
	assert(pthread_create(&id, NULL, func, (void *) 123) == 0);
	printf("M : wait for child thread!\n");
	assert(pthread_join(id, (void **) &result) == 0);
	printf("M : get child thread value!\n");
	assert(result == 123);
	printf("M : over!\n");
	return 0;
}

 

  结果是:

M : create child thread!
M : wait for child thread!
C : thread start!
C : thread end!
M : get child thread value!
M : over!
 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics