Hi Noah, I wrote: > In each of these cases, we have two options: (1) synchronize on every > access of the lazily-initialized variable (including reads), or (2) > abandon lazy initialization.
Noah Lavine <noah.b.lav...@gmail.com> writes: > I've only read the most recent article you posted, but if I understand > correctly, there is a third option: (3) somehow find a way to generate > a portable memory barrier instruction. Is that currently possible? If we were to do that, we'd have to add memory barriers in two places: (1) after writing to the lazily-initialized variable, and (2) before reading from it. While memory barriers are somewhat more efficient than mutexes, they are still very expensive. As for portability, C11 is the first C standard to support memory barriers. For now, our best bet would probably be to use libatomic_ops, which is also used by libgc. > Probably option (2) is best if we can do it. Agreed. Unfortunately, in these cases option (2) would significantly increase the number of modules that need to be loaded at initialization time. That's why I reluctantly chose option (1). Regards, Mark