码迷,mamicode.com
首页 > Windows程序 > 详细

windows下静态编译pthread

时间:2015-03-31 14:36:08      阅读:244      评论:0      收藏:0      [点我收藏+]

标签:

1. Building the library as a statically linkable library
-----------------------------------------------------

General: PTW32_STATIC_LIB must be defined for both the library build and the
application build. The makefiles supplied and used by the following ‘make‘
command lines will define this for you.

MSVC (creates pthreadVCn.lib as a static link lib):

nmake clean VC-static


MinGW32 (creates libpthreadGCn.a as a static link lib):

make clean GC-static


Define PTW32_STATIC_LIB when building your application. Also, your
application must call a two non-portable routines to initialise the
some state on startup and cleanup before exit. One other routine needs
to be called to cleanup after any Win32 threads have called POSIX API
routines. See README.NONPORTABLE or the html reference manual pages for
details on these routines:

BOOL pthread_win32_process_attach_np (void);
BOOL pthread_win32_process_detach_np (void);
BOOL pthread_win32_thread_attach_np (void); // Currently a no-op
BOOL pthread_win32_thread_detach_np (void);


The tests makefiles have the same targets but only check that the
static library is statically linkable. They don‘t run the full
testsuite. To run the full testsuite, build the dlls and run the
dll test targets.

=============================================

2. 使用pthread-win32静态库
使用pthread-win32静态库要注意:
1) 在程序中要定义宏PTW32_STATIC_LIB
2) pthread-win32静态库中没有做attach和detach操作,要程序员来完成该任务,
否则线程有能成功创建。具体如下:
在程序入口(通常是main函数)处调用如下两个函数
pthread_win32_process_attach_np();
pthread_win32_thread_attach_np();
程序结束时调用
pthread_win32_thread_detach_np();
pthread_win32_process_detach_np();

没办法,windows系统有很多标准它都不支持,写起来就要麻烦点。
可以简单地这样处理:

a) 定义程序结束时的处理函数
#ifdef PTW32_STATIC_LIB
void pthread_win32_detach(void)
{
pthread_win32_thread_detach_np();
pthread_win32_process_detach_np();
}
#endif

b) 在程序入口处调用如下
#ifdef PTW32_STATIC_LIB
pthread_win32_process_attach_np();
pthread_win32_thread_attach_np();
atexit(pthread_win32_detach);
#endif

windows下静态编译pthread

标签:

原文地址:http://www.cnblogs.com/guoxiaoqian/p/4380637.html

(0)
(1)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!