2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

スレッドに関するメモ

Posted at

変数

すべてのスレッドは同じアドレス空間で動く ので 大域変数と静的変数は共有される。

スタックはスレッド個別に存在する ので ローカル変数は共有しない。

排他制御

EnterCriticalSection()
排他制御開始
同じスレッドであれば実行を妨げない。違うスレッドが排他中であれば解放まで待つ。
待ちたくない場合はTryEnterCriticalSection()を使う。

tls

スレッド固有の静的変数をもつためのしくみ
kernel32.dllで実装されている

TlsAlloc() 確保してidを取得
TlsSetValue(id,&data) データをセット
TlsGetValue(id) データを取得
TlsFree(id) 領域を開放
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?