タグ

セマフォに関するadvblogのブックマーク (2)

  • The Little Book of Semaphores – Green Tea Press

    by Allen B. Downey Download The Little Book of Semaphores in PDF. The Little Book of Semaphores is a free (in both senses of the word) textbook that introduces the principles of synchronization for concurrent programming. In most computer science curricula, synchronization is a module in an Operating Systems class. OS textbooks present a standard set of problems with a standard set of solutions, b

  • セマフォを使った排他制御

    排他制御とは、あるメモリやある操作を、同時に複数のプログラムからアクセスあるいは実行させないようにするための処理です。 プロセス間で排他制御をするには、グローバル変数は使えません。グローバル変数はプロセスごとにもつものだからです。 共有メモリの1バイトをフラグとして使ったりすると、フラグを立てた瞬間に2つ以上のプロセスが同時に 走ってしまう危険性があります。ファイルを作成し、ファイルが存在するか否かをフラグに使っても同じような 問題があります。 セマフォとは以上のような問題点を解決するための仕組みです。セマフォはOSが用意するグローバルなフラグのようなもので、 そのフラグを待っているプロセスが複数あったとしても、セマフォから実行の許可が得られるプロセスを1つ に制限させることができます。 サンプルプログラムを考えます。このプログラムは親が500バイト共有メモリを作成します。 そして、for

  • 1