[haiku-commits] Re: haiku: hrev46679 - src/kits/network/libnetapi headers/os/net

  • From: Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Thu, 16 Jan 2014 10:16:14 +0100 (CET)

> On January 16, 2014 at 9:42 AM Adrien Destugues <pulkomandy@xxxxxxxxx> wrote:
> sInitOnce is a vint32 (volatile), which I was told was enough when I wrote
> the Locale Kit catalog loading which works the same way. If that actually
> doesn't work, I can implement it using pthread init_once features, and also
> fix the catalog loading to do the same.

Please just start to think for yourself before believing (or maybe just
misunderstanding) what someone else told you!

How could this possibly work?

You read the value (atomically on x86 platform), test it, and then write to it
again (again, atomically on the x86 platform). Inbetween, another thread has all
the time in the world to do the same. But even if you had used some atomic_*()
function to read/evaluate/write the value atomically, and prevent that issue,
you still have the problem that the other thread would then believe to be able
to use the context when it cannot, as it's simply not yet initialized at the
point sInitOnce has been set.

Bye,
   Axel.

Other related posts: