52c Subj : Memory reordering problem (or is it?) To : comp.programming.threads From : Maciej Sobczak Date : Wed Jun 15 2005 10:41 am Hi, Let's consider two threads (ThreadA and ThreadB), ThreadA executing the following (C++, but treat it as pseudocode): int i = 7; int j = 0; // ... j = i; i = 0; Absent any synchronization, I understand that due to memory reordering (and no visibility between threads guarantee in general), ThreadB might at some point see this: i == 0 and j == 0 Now, consider that ThreadA does the following instead: int *p1 = new int; int *p2 = 0; // ... p2 = p1; p1 = 0; and that ThreadB is a simple Garbage Collector that scans the program memory (well, it's own *perception* of the memory) for whatever it finds to be a pointer and uses the following condition: p1 == 0 and p2 == 0 as an indication that it is OK to reclaim the dynamic object and its memory. Gray smoke after that. I'm not an expert in today's GC technology, but considering the fact that it has a lot to do with threads, I would like to ask you whether this is considered to be a problem and what GC (or the language and its runtime) can do to avoid this. Regards, -- Maciej Sobczak : http://www.msobczak.com/ Programming : http://www.msobczak.com/prog/ . 0