VC

スレッド作成する

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
}


あなたのお住まいの地域で最安のブロードバンド選び

コメント:



(画像の文字列を入力して下さい)

トップ   編集 凍結 差分 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2019/12/02 (月) 12:43:22 (1627d)

e[NȂECir Yahoo yV LINEf[^[Ōz500~`I
z[y[W ̃NWbgJ[h COiq@COsیI COze