nisse@lysator.liu.se (Niels Möller) writes:
Another question: We need some kind of memory barrier when writing and/or reading the initialized flag. The (unlikely) failure case is a thread reading the initialized flag, getting 1, and then reading one of the function pointers, and getting a too old value.
After discussing this on another forum, I've been told that the x86 architecture is strongly ordered (as long as one doesn't use certain instructions, like "non-temporal store"). So a plain store to a volatile int should to, with no memory barriers.
Case of ARM will be different, since it has a weaker memory model.
See also http://lwn.net/Articles/252110/
Regards, /Niels