スレッド作成する †pthread_create(&thr, ...) スレッドを廃棄する †pthread_cancel(thr) スレッドをロックする †// グローバル変数 pthread_mutex_t mutex_for_some_value = PTHREAD_MUTEX_INITIALIZER; void * thread_talk(void * arguments) { for (int x = 1 ; x< 500 ; x++) { //ロック pthread_mutex_lock( &mutex_for_some_value ); some_value++; //アンロック pthread_mutex_unlock( &mutex_for_some_value ); } pthread_exit(NULL); thread_local †「Thread Local Storage」と類似な機能である、スレッド毎のグローバル変数。 thread_local int j = 0; void foo() { m.lock(); j++; // j is now 1, no matter the thread. j is local to this thread. m.unlock(); } void func() { j = 0; std::thread t1(foo); std::thread t2(foo); t1.join(); t2.join(); // j still 0. The other "j"s were local to the threads } あなたのお住まいの地域で最安のブロードバンド選び コメント: |