日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

pthread-win32在VC2005下的使用

發布時間:2023/12/10 c/c++ 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 pthread-win32在VC2005下的使用 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

pthread-win32是一個在Win32環境下的Unix POSIX線程庫的移植. 有了它, 可以比較方便的移植Unix/Linux多線程程序到Windows下. 在VC2005下使用也很簡單:

下載, 地址是?http://sourceware.org/pthreads-win32

里面include目錄中是頭文件, lib目錄中是.lib和.dll文件.

在VC項目的屬性中, 分別加入.h文件的目錄, 和.lib文件的目錄, 并在link選項中加入.lib庫:







?

寫一段最簡單的代碼來測試(創建一個線程, 輸出一點東西):

#include "stdafx.h"

#include <pthread.h>

?

struct dt {

????int a;

????int b;

};

?

void* thread_function(void* arg);

?

int _tmain(int argc, _TCHAR* argv[])

{

????int result0;

????dt data0;

????data0.a = 0;

????data0.b = 1;

?

????pthread_t a_thread;

????result0 = pthread_create(&a_thread, NULL, thread_function, (void*)&data0);

????if (result0 != NULL) {

????????printf("error creating thread0!");

????????return 1;

????}

????getchar();

}

?

void* thread_function(void* arg) {

????dt* data = (dt*)arg;

????printf("%d %d", data->a, data->b);

????return NULL;

}

?

?

編譯, 鏈接, 運行, OK.

?

注意: 需要把pthreadvc2.dll copy到Debug或者Release目錄, 否則可能會出現找不到dll的錯誤.

?

另外pthread2提供了不同的.lib以及相對應的.dll,

?

????pthread[VG]{SE,CE,C}c.dll
pthread[VG]{SE,CE,C}c.lib

?

含義為

?

????[VG] 編譯器種類
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 = 兼用性 - 和pthread2兼容, 不和舊版本pthread1兼容.

?

???詳細請參照pthread的readme.

總結

以上是生活随笔為你收集整理的pthread-win32在VC2005下的使用的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。