Is this thread safe?

Walter Bright newshound1 at digitalmars.com
Fri Jul 11 18:26:48 PDT 2008


dsimcha wrote:
> Never mind, I see at least one reason why my last post would be incorrect.  The
> length variable could be set out-of-order before all of the factorials up to
> length are calculated.  Is there any simple way to write this function so it's
> thread-safe without using synchronized just to access cached results?

No. There are three choices:

1) synchronize it

2) make thread-local versions

3) insert fences with the inline assembler



More information about the Digitalmars-d mailing list