Memory Barriers and Semaphores
?
?

Keyboard Navigation

Global Keys

[, < / ], > Jump to previous / next episode
W, K, P / S, J, N Jump to previous / next timestamp
t / T Toggle theatre / SUPERtheatre mode
V Revert filter to original state Y Select link (requires manual Ctrl-c)

Menu toggling

q Quotes r References f Filter y Link c Credits

In-Menu and Index Controls

a
w
s
d
h j k l


Esc Close menu / unfocus timestamp

Quotes and References Menus and Index

Enter Jump to timestamp

Quotes, References and Credits Menus

o Open URL (in new tab)

Filter Menu

x, Space Toggle category and focus next
X, ShiftSpace Toggle category and focus previous
v Invert topics / media as per focus

Filter and Link Menus

z Toggle filter / linking mode

Credits Menu

Enter Open URL (in new tab)
0:35Recap/Review
0:35Recap/Review
0:35Recap/Review
2:45Yesterday's TODOs
2:45Yesterday's TODOs
2:45Yesterday's TODOs
4:00TODO 1: Ordering of writes
4:00TODO 1: Ordering of writes
4:00TODO 1: Ordering of writes
6:33CompletePastWritesBeforeFutureWrites
6:33CompletePastWritesBeforeFutureWrites
6:33CompletePastWritesBeforeFutureWrites
10:22Looking up memory fences
10:22Looking up memory fences
10:22Looking up memory fences
12:10Venturing into Visual Studio's include folder
12:10Venturing into Visual Studio's include folder
12:10Venturing into Visual Studio's include folder
13:20Putting in an actual CPU barrier
13:20Putting in an actual CPU barrier
13:20Putting in an actual CPU barrier
14:32Where do we go from here?
14:32Where do we go from here?
14:32Where do we go from here?
15:00Volatile introduction
15:00Volatile introduction
15:00Volatile introduction
18:43TODO 2: Interlocked writes
18:43TODO 2: Interlocked writes
18:43TODO 2: Interlocked writes
20:10Looking up InterlockedIncrement
20:10Looking up InterlockedIncrement
20:10Looking up InterlockedIncrement
21:37TODO 3: Already taken care of by volatile
21:37TODO 3: Already taken care of by volatile
21:37TODO 3: Already taken care of by volatile
21:54TODO 4: Ordering of reads
21:54TODO 4: Ordering of reads
21:54TODO 4: Ordering of reads
23:24Checking our work
23:24Checking our work
23:24Checking our work
24:20NB: Don't use all 16 hyperthreads!
24:20NB: Don't use all 16 hyperthreads!
24:20NB: Don't use all 16 hyperthreads!
25:45Job completion
25:45Job completion
25:45Job completion
28:40Waiting for all the threads to complete
28:40Waiting for all the threads to complete
28:40Waiting for all the threads to complete
30:50Suspending and resuming threads
30:50Suspending and resuming threads
30:50Suspending and resuming threads
34:51Semaphores
34:51Semaphores
34:51Semaphores
37:28WaitForSingleObject for suspending
37:28WaitForSingleObject for suspending
37:28WaitForSingleObject for suspending
40:35Creating the semaphore
40:35Creating the semaphore
40:35Creating the semaphore
44:24Problem: Threads never wake up!
44:24Problem: Threads never wake up!
44:24Problem: Threads never wake up!
46:50Waking up by releasing the semaphore
46:50Waking up by releasing the semaphore
46:50Waking up by releasing the semaphore
53:27How we'll use the semaphore
53:27How we'll use the semaphore
53:27How we'll use the semaphore
54:26Testing the semaphore
54:26Testing the semaphore
54:26Testing the semaphore
56:50Work for tomorrow
56:50Work for tomorrow
56:50Work for tomorrow
57:13Q&A
🗩
57:13Q&A
🗩
57:13Q&A
🗩
58:24d7samurai In the visual studio output window you can right click and deselect some of the stuff
🗪
58:24d7samurai In the visual studio output window you can right click and deselect some of the stuff
🗪
58:24d7samurai In the visual studio output window you can right click and deselect some of the stuff
🗪
58:56cubercaleb Why does this have to be so complicated??
🗪
58:56cubercaleb Why does this have to be so complicated??
🗪
58:56cubercaleb Why does this have to be so complicated??
🗪
59:37rc1290 Why did you put the memory barrier in a macro when it's platform-specific code?
🗪
59:37rc1290 Why did you put the memory barrier in a macro when it's platform-specific code?
🗪
59:37rc1290 Why did you put the memory barrier in a macro when it's platform-specific code?
🗪
1:00:07robrobby After the sleep, some threads still pushed several strings, leaving out some of the other threads
🗪
1:00:07robrobby After the sleep, some threads still pushed several strings, leaving out some of the other threads
🗪
1:00:07robrobby After the sleep, some threads still pushed several strings, leaving out some of the other threads
🗪
1:00:56plain_flavored Would Sleep(0) in your spin-lock help anything?
🗪
1:00:56plain_flavored Would Sleep(0) in your spin-lock help anything?
🗪
1:00:56plain_flavored Would Sleep(0) in your spin-lock help anything?
🗪
1:02:35abnercoimbre IMGUI has been trending. Sorry if you get asked this more than you like to.
🗪
1:02:35abnercoimbre IMGUI has been trending. Sorry if you get asked this more than you like to.
🗪
1:02:35abnercoimbre IMGUI has been trending. Sorry if you get asked this more than you like to.
🗪
1:03:07goodjerm When you initially started this project, what were the first 5 things you coded and why?
🗪
1:03:07goodjerm When you initially started this project, what were the first 5 things you coded and why?
🗪
1:03:07goodjerm When you initially started this project, what were the first 5 things you coded and why?
🗪
1:03:22ifingerbangedurcat I missed most of tonight, what does the volatile keyword mean?
🗪
1:03:22ifingerbangedurcat I missed most of tonight, what does the volatile keyword mean?
🗪
1:03:22ifingerbangedurcat I missed most of tonight, what does the volatile keyword mean?
🗪
1:03:47noxy_key How do you plan to maintain cache line coherency between processors? Can physical CPUs share a cache line?
🗪
1:03:47noxy_key How do you plan to maintain cache line coherency between processors? Can physical CPUs share a cache line?
🗪
1:03:47noxy_key How do you plan to maintain cache line coherency between processors? Can physical CPUs share a cache line?
🗪
1:05:03Blackboard: MESI and Cache Coherency
1:05:03Blackboard: MESI and Cache Coherency
1:05:03Blackboard: MESI and Cache Coherency
1:14:15gasto5 Was volatile added in C99?
🗪
1:14:15gasto5 Was volatile added in C99?
🗪
1:14:15gasto5 Was volatile added in C99?
🗪
1:14:37abnercoimbre Wait, so transactional memory wants to simplify concurrent programming by allowing a chunk of load/store instructions to execute in atomically. Have you messed with this?
🗪
1:14:37abnercoimbre Wait, so transactional memory wants to simplify concurrent programming by allowing a chunk of load/store instructions to execute in atomically. Have you messed with this?
🗪
1:14:37abnercoimbre Wait, so transactional memory wants to simplify concurrent programming by allowing a chunk of load/store instructions to execute in atomically. Have you messed with this?
🗪
1:15:05Blackboard: Transactional Memory
1:15:05Blackboard: Transactional Memory
1:15:05Blackboard: Transactional Memory
1:18:58abnercoimbre Transactional memory is often advocated as an easier-to-use replacement for locks that avoids any possibility of a deadlock, so I wanted your thoughts.
🗪
1:18:58abnercoimbre Transactional memory is often advocated as an easier-to-use replacement for locks that avoids any possibility of a deadlock, so I wanted your thoughts.
🗪
1:18:58abnercoimbre Transactional memory is often advocated as an easier-to-use replacement for locks that avoids any possibility of a deadlock, so I wanted your thoughts.
🗪
1:21:04plainflavored Why are we building a generic work distribution when the tiled renderer is designed to cleanly split up the work anyway?
🗪
1:21:04plainflavored Why are we building a generic work distribution when the tiled renderer is designed to cleanly split up the work anyway?
🗪
1:21:04plainflavored Why are we building a generic work distribution when the tiled renderer is designed to cleanly split up the work anyway?
🗪
1:22:45Wrapping things up
🗩
1:22:45Wrapping things up
🗩
1:22:45Wrapping things up
🗩

Memory Barriers and Semaphores

Semaphores:

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 releases 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.

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.