Noah Lavine <[email protected]> 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