guile-devel
[Top][All Lists]
Advanced

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

Re: Thread-unsafe initialization problems in Guile


From: Mark H Weaver
Subject: Re: Thread-unsafe initialization problems in Guile
Date: Tue, 05 Mar 2013 22:50:17 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux)

Noah Lavine <address@hidden> writes:

> I'm not sure I understand the issue, but I think I was imagining
> something like
>
> if (variable == SCM_BOOL_F) {
>   acquire_mutex(var_mutex);
>   if (variable == SCM_BOOL_F) {
>     variable = initialize_variable();
>     memory_barrier();
>   }
>   release_mutex(var_mutex);
> }
>
> That's really just a normal locking scheme with an added memory
> barrier to make sure that all threads see an update after the first
> thread updates the variable. Would that work?

No.  There's no portable memory barrier that can be used only by the
writer of a shared variable.  The reader must also do synchronization in
order to prove the "happens-before" relationship.

    Regards,
      Mark



reply via email to

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