Subj : Re: Memory visibility and synchronization using pipes To : comp.programming.threads From : Joseph Seigh Date : Sat Jan 15 2005 09:24 am On Sat, 15 Jan 2005 12:10:26 +0100, Marcin 'Qrczak' Kowalczyk wrote: > Let's say thread A does this: > - changes a variable > - writes to a pipe > and thread B does this: > - waits until poll() says the pipe can be read > - accesses the variable > (the pipe is used only for this synchronization). > > Is it safe, or the change to the variable may not be seen by the other > thread? I guess write() and poll() are not memory barriers and this is > unsafe. If so, how to fix it in the simplest way? > > I'm using a pipe because thread B uses poll() on other descriptors at > the same time. > Most likely it is safe. Any syscalls and context switches are going to perform memory synchronization. If the pipe is implemented without syscalls, you would need a hardware mechanism that didn't cause or need memory synchronization, e.g. totally ordered uncached memory, which is extremely unlikely. -- Joe Seigh .