How can I be sure that the data written by several CPU cores during mutex lock is synchronized in all L1 caches of all cores? I'm not talking about a variable that represents a lock, I am talking about memory locations that are involved during a lock.
This is for Linux, x86_64, and my code is:
#include <sys/types.h> #include "dlog.h" uint *dlog_line; volatile int dlog_lock; char *dlog_get_new_line(void) { uint val; while(!__sync_bool_compare_and_swap(&dlog_lock, 0, 1)) { val=*dlog_line; if (val==DT_DLOG_MAX_LINES) val=0; *dlog_line=val; } dlog_lock = 0; }
Here, inside the dlog_get_new_line () function, I use the built-in gcc function, so there should not be any problems with acquiring the lock. But how can I guarantee that when the lock is released, the value indicated by * dlog_line extends to the entire L1 cache of all other processor cores in the system?
I do not use pthreads, each process runs on a different cpu core.
Nulik source share