锘??xml version="1.0" encoding="utf-8" standalone="yes"?> pthread[VG]{SE,CE,C}c.dll 鍚箟涓?br>[VG] 緙栬瘧鍣ㄧ綾?br>V - MS VC, or {SE,CE,C} 寮傚父澶勭悊妯″紡 姣斿涓婇潰鐢ㄧ殑pthreadvc2.dll, 鍚箟涓? v = MSVC c = 娌℃湁浣跨敤寮傚父鏈哄埗, 鑰屾槸浣跨敤setjump/longjmp 2 = 鍏肩敤鎬?- 鍜宲thread2鍏煎, 涓嶅拰鏃х増鏈琾thread1鍏煎. 璇︾粏璇峰弬鐓thread鐨剅eadme. 浣嗗湪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
official site: http://sourceware.org/pthreads-win32/.
source co
1. 緙栬瘧:
铏界劧婧愮爜鍖呴噷鎻愪緵浜唙c6鐨勯」鐩枃浠? 浣嗘槸鎵撲笉寮鐨? 鍙兘鐢╪make. 榛樿鐨勪細鍛婅瘔浣犱竴鍫唍make鍙傛暟鐨?
鎴戞墍瑕佺敤鐨勬槸緙栬瘧鎴恠tatic鐨刲ibrary, 鎵浠ヨ緭鍏?nmake clean VC-static", 緙栬瘧寰堝揩鐨? 涓嶈繃榛樿浼氶摼鎺ュ埌VC鐨刢rt, 鎴戜滑闇瑕佷慨鏀瑰畠鐨刴akefile. 鎵懼埌CFLAGS閭d竴琛? 鎶?/MD"鏀規垚"/MT".
2. 欏圭洰:
璇?. 鏈夊ソ澶氬湴鏂硅鏀圭殑.
a) 褰撶劧鏄痸s璺緞鐨刬nclude鍟? lib鍟?. 鑷繁鍔?
b) 欏圭洰鐨刢rt璁劇疆鎴?/MT"鍜?/MTd". 棰濆鐨刲ib鍔? pthreadVC2(d).lib ws2_32.lib
c) preprocesser瀹氫箟鐨勫湴鏂? 鍔犱竴涓?#8220;PTW32_STATIC_LIB”瀹? 涓嶇劧link鐨勬椂鍊欎細鎵句笉鍒皊ymbol鐨?
d) 濂戒簡, 浣犲彲浠oding浜? 闅忎究pthread_create()涓鎶婂惂.
3. 緙栫爜:
鍡棷.. 濡傛灉鐪熺殑鐩存帴pthread_create()鐨勮瘽鍙槸浼歛ccess violation鐨勫憖. win32涓嬬殑綰跨▼寰堣寮傜殑, 鍍弚insock涓鏍? 璋冪敤浠諱綍鍏跺畠鍑芥暟涔嬪墠蹇呴』璋冪敤pthread_win32_process_attach_np(), 緇撴潫鍚庡繀欏昏皟鐢╬thread_win32_process_detach_np(). 浠g爜澶ф灝辨槸榪欐牱鐨?
1. 涓嬭澆pthreads win32婧愪唬鐮侊細
ftp://sourceware.org/pub/pthreads-win32/pthreads-w32-2-8-0-release.tar.gz
2. 緙栬瘧闈欐佸簱錛?br>make clean GC-static
鍦ㄦ牴鐩綍涓嬮潰鐢熸垚libpthreadGC2.a
3. 灝嗙敓鎴愮殑libpthreadGC2.a鎷瘋礉鍒癿ingw搴撶洰褰曚笅錛屽皢pthread.h, sched.h, semaphore.h鎷瘋礉鍒癐NCLUDE鐩綍涓?br>4. 浣跨敤libpthread搴擄紝
鍦ㄧ▼搴忚搗濮嬪瀵筶ibpthread浣滃垵濮嬪寲錛?br>#if defined(PTW32_STATIC_LIB)
ptw32_processInitialize();
#endif
5. 緙栬瘧鏃剁‘淇濅紶鍏?DPTW32_STATIC_LIB錛岄摼鎺ユ椂鍔犲叆-lpthreadGC2錛?OK錛?br>
http://hi.baidu.com/lff0305/blog/item/2a55e7366ebba6360b55a942.html
pthread2鎻愪緵浜嗕笉鍚岀殑.lib浠ュ強鐩稿搴旂殑.dll,
pthread[VG]{SE,CE,C}c.lib
G - GNU 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.
http://blog.csdn.net/psusong/archive/2010/01/14/5189659.aspx
pthread 闈欐佺紪璇戠増鏈湪Windows涓嬩嬌鐢ㄦ椂鐨勬敞鎰忎簨欏?
浣滀負閫氱敤鐨勮法騫沖彴楂樻ц兘綰跨▼搴擄紝鍦ㄥ緢澶氳法騫沖彴鐨勯」鐩腑閮藉彲浠ョ湅瑙乸thread鐨勮韓褰便俻thread鏈韓鐨勫疄鐜版瘮杈冧紭闆咃紝APIs浣跨敤璧鋒潵涔熷緢鏂逛究銆?/p>
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.
]]>