pthread[VG]{SE,CE,C}c.dll
pthread[VG]{SE,CE,C}c.lib
鍚箟涓?br>[VG] 緙栬瘧鍣ㄧ綾?br>V - MS VC, or
G - GNU C
{SE,CE,C} 寮傚父澶勭悊妯″紡
SE - Structured EH, or
CE - C++ EH, or
C - no exceptions - uses setjmp/longjmp
c - DLL compatibility number indicating ABI and API
compatibility with applications built against
any snapshot with the same compatibility number.
See 'Version numbering' below.
姣斿涓婇潰鐢ㄧ殑pthreadvc2.dll, 鍚箟涓?
v = MSVC
c = 娌℃湁浣跨敤寮傚父鏈哄埗, 鑰屾槸浣跨敤setjump/longjmp
2 = 鍏肩敤鎬?- 鍜宲thread2鍏煎, 涓嶅拰鏃х増鏈琾thread1鍏煎.
璇︾粏璇峰弬鐓thread鐨剅eadme.
http://blog.csdn.net/psusong/archive/2010/01/14/5189659.aspx
pthread 闈欐佺紪璇戠増鏈湪Windows涓嬩嬌鐢ㄦ椂鐨勬敞鎰忎簨欏?
浣滀負閫氱敤鐨勮法騫沖彴楂樻ц兘綰跨▼搴擄紝鍦ㄥ緢澶氳法騫沖彴鐨勯」鐩腑閮藉彲浠ョ湅瑙乸thread鐨勮韓褰便俻thread鏈韓鐨勫疄鐜版瘮杈冧紭闆咃紝APIs浣跨敤璧鋒潵涔熷緢鏂逛究銆?/p>
浣嗗湪Windows涓嬩嬌鐢ㄩ潤鎬佺紪璇戠殑pthread鏃惰鐗瑰埆娉ㄦ剰涓涓嬶紝蹇呴』鏄懼紡鐨勮皟鐢ㄥ涓嬪洓涓嚱鏁幫紝鍚﹀垯pthread鐢ㄥ埌鐨勪竴浜涘叏灞鍙橀噺浼氭病鏈夎鍒濆鍖栵紝瀵艱嚧鎵鏈夌殑pthread鐨凙PIs璋冪敤閮絚rash.
BOOL pthread_win32_process_attach_np (void);
BOOL pthread_win32_process_detach_np (void);
BOOL pthread_win32_thread_attach_np (void);
BOOL pthread_win32_thread_detach_np (void);
pthread瀹樻柟鏂囨。瀵規鏈夊涓嬬殑鏄庣‘璇存槑錛?/p>
These functions contain the code normally run via dllMain
when the library is used as a dll but which need to be
called explicitly by an application when the library
is statically linked.
You will need to call pthread_win32_process_attach_np() before
you can call any pthread routines when statically linking.
You should call pthread_win32_process_detach_np() before
exiting your application to clean up.
pthread_win32_thread_attach_np() is currently a no-op, but
pthread_win32_thread_detach_np() is needed to clean up
the implicit pthread handle that is allocated to a Win32 thread if
it calls certain pthreads routines. Call this routine when the
Win32 thread exits.
These functions invariably return TRUE except for
pthread_win32_process_attach_np() which will return FALSE
if pthreads-win32 initialisation fails.
閫氳繃鍑芥暟鐨勫悕瀛楁垜浠笉闅劇寽嫻嬪嚭濡備笅璋冪敤欏哄簭
鍦ㄧ▼搴忓紑濮嬬殑鏃跺欒璋冪敤錛?/p>
BOOL pthread_win32_process_attach_np (void);
BOOL pthread_win32_thread_attach_np (void);
鍦ㄧ▼搴忛鍑烘椂瑕佽皟鐢細
BOOL pthread_win32_thread_detach_np (void);
BOOL pthread_win32_process_detach_np (void);
姣旇緝閫氱敤鐨勫仛娉曟槸鍦ㄦā鍧桳oad鍜孶nLoad鐨勬椂鍊欏仛榪欎釜attach鍜宒etach鎿嶄綔錛屽涓嬮潰鎵紺猴細
/* Callback for our DLL so we can initialize pthread */
BOOL WINAPI DllMain( HANDLE hinstDLL, DWORD fdwReason, LPVOID lpvReserved )
{
#ifdef PTW32_STATIC_LIB
switch( fdwReason )
{
case DLL_PROCESS_ATTACH:
pthread_win32_process_attach_np();
case DLL_THREAD_ATTACH:
pthread_win32_thread_attach_np();
break;
case DLL_THREAD_DETACH:
pthread_win32_thread_detach_np();
break;
case DLL_PROCESS_DETACH:
pthread_win32_thread_detach_np();
pthread_win32_process_detach_np();
break;
}
#endif
return TRUE;
}
娉ㄦ剰錛?PTW32_STATIC_LIB 瀹忎負pthread闈欐佺紪璇戠殑鏍囧織錛岃繖涓彲浠ラ氳繃pthread.h鐨勯厤緗垨鑰匔FLAGS浼犻掕繘鏉ャ?br>涓嬮潰鏄痯thread鐨勫畼鏂圭殑dll.c鐨勫疄鐜?br>BOOL WINAPI
DllMain (HINSTANCE hinstDll, DWORD fdwReason, LPVOID lpvReserved)
{
BOOL result = PTW32_TRUE;
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
result = pthread_win32_process_attach_np ();
break;
case DLL_THREAD_ATTACH:
/*
* A thread is being created
*/
result = pthread_win32_thread_attach_np ();
break;
case DLL_THREAD_DETACH:
/*
* A thread is exiting cleanly
*/
result = pthread_win32_thread_detach_np ();
break;
case DLL_PROCESS_DETACH:
(void) pthread_win32_thread_detach_np ();
result = pthread_win32_process_detach_np ();
break;
}
return (result);
} /* DllMain */
涔熷氨鏄pthread瀹樻柟浠g爜鍦ㄥ姩鎬佺紪璇戠殑鐗堟湰涓富鍔ㄥ仛浜嗚繖涓猘ttach鍜宒etach鎿嶄綔銆?br>鑰岄潤鎬佺紪璇戠増鏈敱浜庢病鏈変竴涓悎閫傜殑鍦版柟鏉ュ仛榪欎歡浜嬶紝灝卞皢attach鍜宒etach鐨勭殑鎿嶄綔鎵旂粰鐢ㄦ埛鏉ュ畬鎴愪簡銆?br>涓婇潰鐨勪唬鐮佹槸閽堝璋冪敤鏂規槸Dll鐨勬儏鍐靛仛鐨勫垵濮嬪寲錛屽鏋滆皟鐢ㄦ柟涓嶆槸Dll鍛紵瀵規鍙互鍙傜収濡備笅鍋氭硶錛岃櫧鐒跺緢鏆村姏錛屼絾寰堢畝鍗曪紝鍙互宸ヤ綔
1錛夊畾涔夊涓嬪嚱鏁?br>#ifdef PTW32_STATIC_LIB
static void detach_ptw32(void)
{
pthread_win32_thread_detach_np();
pthread_win32_process_detach_np();
}
#endif
2錛夊湪浣犵殑涓葷▼搴忕殑鍏ュ彛澶勶紝涓鑸岃█鏄痬ain()涓仛濡備笅璋冪敤鍗沖彲
#ifdef PTW32_STATIC_LIB
pthread_win32_process_attach_np();
pthread_win32_thread_attach_np();
atexit(detach_ptw32);
#endif
涔熷氨鏄敤atexit()灝哾etach宸ヤ綔鎸傛帴鍒扮▼搴忎腑鍘伙紝浣垮緱紼嬪簭鍦ㄩ鍑虹殑鏃跺欏彲浠ュpthread榪涜detach.