C++ multi-thread簡易範例
#include <windows.h> #include <process.h> #include <iostream> using namespace std; void threadProc(void* p) { char *data = (char*)p; cout << "Starting -- " << data << endl; Sleep(3000); cout << "Ending -- " << data << endl; delete [] data; } int main() { char *Data1 = new char[99]; strcpy(Data1, "Testing 1"); _beginthread(threadProc, 0, (void*)Data1 ); char *Data2 = new char[99]; strcpy(Data2, "Testing 2"); _beginthread(threadProc, 0, (void*)Data2 ); Sleep(3000); }
作者:huaning提供~~
如果想要在windows底下也使用pthread的話可以下載下面這一包
pthread-w32.zip
裡面還包含了一個使用MinGW/DEV-C++來編譯(makefile)的範例。
全站熱搜
留言列表