cinera_handmade.network/cmuratori/hero/code/code124_template.html

30 lines
1.7 KiB
HTML
Raw Normal View History

<html>
<head>
<!-- __CINERA_INCLUDES__ -->
</head>
<body>
<div id="cinera">
<!-- __CINERA_MENUS__ -->
<!-- __CINERA_PLAYER__ -->
</div>
<!-- __CINERA_SCRIPT__ -->
<article id="video-notes">
<h1><!-- __CINERA_TITLE__ --></h1>
<p>Semaphores:</p>
<p>A semaphore is essentially a number that the operating system keeps track of, that can be incremented and decremented.
When you wait for a semaphore, you&#39;re essentially telling the OS to let you know when the semaphore number becomes
greater than zero. Once it does, then the Wait() call will return and the thread can do something. Calling
ReleaseSemaphore(), maybe a little counterintuitively, increments the semaphore, allowing any threads waiting on it to
continue working. (Thus, it <em>releases</em> those threads to do work). It doesn&#39;t actually change the state of the semaphore
other than making the number go up. The semaphore number goes down when a thread has successfully Wait()ed for the
semaphore. In cases like the one demonstrated on stream, this usually means the semaphore number will go up/down really
fast and stick close to 0 as most of the time the threads are waiting for the semaphore to increment.</p>
<p>What this allows you to do is tell several threads at once that some work is ready without having to signal to each one
individually. As long as each one is waiting on the same semaphore object, they&#39;ll all know when there&#39;s more work to be
done.</p>
</article>
</body>
</html>