多執行緒示例

2021-08-16 15:55:17 字數 1462 閱讀 8856

#include#include #include pthread_t thread [2];

pthread_mutex_t mut;

int num=0;

void* thread1(void *args)

pthread_exit(null);

}void* thread2(void *args)

pthread_exit(null);

}void thread_create()

void thread_wait()

if(0!=thread[1])

}int main()

這裡,我時用liunx下,cmakelists.txt 進行配置檔案;

cmake_minimum_required(version 3.9)

project(code)

set(cmake_cxx_standard 11)

add_executable(code code/main.cpp)

target_link_libraries(code pthread)

如果不
target_link_libraries(code pthread)
會出現的錯誤為:

cmakefiles/code.dir/code/main.cpp.o:在函式『thread_create()』中:

/home/shenying/code/code/main.cpp:34:對『pthread_create』未定義的引用

/home/shenying/code/code/main.cpp:38:對『pthread_create』未定義的引用

cmakefiles/code.dir/code/main.cpp.o:在函式『thread_wait()』中:

/home/shenying/code/code/main.cpp:45:對『pthread_join』未定義的引用

/home/shenying/code/code/main.cpp:49:對『pthread_join』未定義的引用

collect2: error: ld returned 1 exit status

cmakefiles/code.dir/build.make:94: recipe for target 'code' failed

make[3]: *** [code] error 1

cmakefiles/makefile2:67: recipe for target 'cmakefiles/code.dir/all' failed

make[2]: *** [cmakefiles/code.dir/all] error 2

cmakefiles/makefile2:79: recipe for target 'cmakefiles/code.dir/rule' failed

make[1]: *** [cmakefiles/code.dir/rule] error 2

多執行緒簡單示例。。。

插入兩個list box,分別為 idc list1 和 idc list2 再插入乙個按鈕,為 idc button1 caption為 run 效果圖如下 雙擊 run 按鈕,新建 onbtnrun 函式。如下 void cmultthreadsdlg onbtnrun 在cmultthread...

多執行緒簡單示例

原文 多執行緒簡單示例 using system using system.collections.generic using system.linq using system.text using system.threading using system.runtime.remoting.mes...

Python多執行緒示例

直接使用threading.thread進行多執行緒實現,其中target為要執行的方法或函式,args為引數列表 方法或函式需要的值 結尾加 因為是元組。def pa n for i in range 10 time.sleep 2 print 這是執行緒 str n defpa2 n for i...