2018-01-08 22:10:24 +00:00
|
|
|
<html>
|
|
|
|
<head>
|
2018-01-15 22:23:46 +00:00
|
|
|
<!-- __CINERA_INCLUDES__ -->
|
2018-01-08 22:10:24 +00:00
|
|
|
</head>
|
|
|
|
<body>
|
2018-01-15 22:08:37 +00:00
|
|
|
<div id="cinera">
|
|
|
|
<!-- __CINERA_MENUS__ -->
|
|
|
|
<!-- __CINERA_PLAYER__ -->
|
2018-01-15 22:23:46 +00:00
|
|
|
|
|
|
|
<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'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'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'll all know when there's more work to be
|
|
|
|
done.</p>
|
|
|
|
</article>
|
2018-01-15 22:08:37 +00:00
|
|
|
</div>
|
|
|
|
<!-- __CINERA_SCRIPT__ -->
|
2018-01-08 22:10:24 +00:00
|
|
|
</body>
|
|
|
|
</html>
|