29 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			HTML
		
	
	
	
			
		
		
	
	
			29 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			HTML
		
	
	
	
<html>
 | 
						|
    <head>
 | 
						|
        <!-- __CINERA_INCLUDES__ -->
 | 
						|
    </head>
 | 
						|
    <body>
 | 
						|
        <div>
 | 
						|
            <!-- __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'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>
 | 
						|
    </body>
 | 
						|
</html>
 |