[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Some introductory docs about C level threading

From: Ken Raeburn
Subject: Re: Some introductory docs about C level threading
Date: Wed, 9 Feb 2005 13:10:59 -0500

On Feb 9, 2005, at 07:13, Marius Vollmer wrote:
And volatile declarations may fix the possibility of storing
incomplete values, but I don't think it would deal with the
cross-thread memory access ordering issue.
As long as accesses to SCM values are atomic, the ordering of
loads/stores across threads can be arbitrary.

I think someone might be tempted to do something like:

thread 1, on cpu 1, with guile core mutex locked:

(precondition: z is a pair, SCM_CAR(z) is a pair)
allocate cons cell x
fill in = v1
fill in x.cdr = v2

thread 2, on cpu 2, running without lock:

set t = SCM_CAR(z) # atomic, so we always get before or after, right?
read SCM_CAR(t) # should Just Work?

With weak memory ordering, and no locking during this sequence in either thread, I don't think we get any guarantee that SCM_CAR(t) will get v1 instead of the uninitialized contents of the cons cell as pulled off of the free list. Especially if it's one that cpu 2 happened to examine recently (perhaps it ran the GC pass) and thus has it in cache. I think you need a memory synchronization operation in each to guarantee this.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]