Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How often does processor cache flush?

Say I have a casual single-byte variable. I think on pretty much all systems single-byte operations are atomic, but if not please let me know. Now, say one thread updates this variable. How long should I expect/prepare for this update to appear in the other threads? I know I can put the update around mutexes/locks/barriers to make sure it's synchronized everywhere, but I'm curious about this. The wait time probably varies depending on whether the other threads are on separate processors/cores, and maybe depending on processor type.

Am I being logical for wondering this or have I greatly misunderstood something?

like image 816
slartibartfast Avatar asked Dec 20 '22 19:12

slartibartfast


1 Answers

Memory is synchronized as soon as you call a synchronization primitive/memory barrier such as pthread_mutex_lock. Aside from that, you should not assume any synchronization unless you're using C11 atomic types.

like image 115
R.. GitHub STOP HELPING ICE Avatar answered Dec 24 '22 01:12

R.. GitHub STOP HELPING ICE