Gio*_*hal 8 c++ multithreading pthreads boost-thread c++11
关于C/C++中线程的问题......
C++ 0x语法
#include <thread>
void dummy() {}
int main(int, char*[]) {
std::thread x(dummy);
std::thread y(dummy);
...
return 0;
}
Run Code Online (Sandbox Code Playgroud)
有多少线程?两个(x和y)或三个(x,y和main)?我可以打电话给this_thread::yield()主?我this_thread::get_id()在主要电话中得到什么?
pthread语法
#include <pthread.h>
void dummy() {}
int main(int, char*[]) {
pthread_t x, y;
pthread_create(&x, NULL, &dummy, NULL);
pthread_create(&y, NULL, &dummy, NULL);
...
return 0;
}
Run Code Online (Sandbox Code Playgroud)
有多少线程?两个(x和y)或三个(x,y和main)?我可以打电话给pthread_yield()主?我pthread_self()在主要电话中得到什么?
提升语法
#include <boost/thread>
void dummy() {}
int main(int, char*[]) {
boost::thread x(dummy);
boost::thread y(dummy);
...
return 0;
}
Run Code Online (Sandbox Code Playgroud)
有多少线程?两个(x和y)或三个(x,y和main)?我可以打电话给boost::this_thread::yield()主?我boost::this_thread::get_id()在主要电话中得到什么?
Col*_*ill 25
在每种情况下,您都创建了两个额外的线程,因此您有三个(x,y和main).您将在每个线程上获得不同的ID,包括main中的调用.
| 归档时间: |
|
| 查看次数: |
3905 次 |
| 最近记录: |