[Reflex] Thread safety

From: Jean-Francois Bastien <jfbastien_at_cae.com>
Date: Wed, 23 Jan 2008 09:33:10 -0500


Good morning,

I've been digging a bit in the Reflex implementation code and I've noticed that Reflex doesn't seem to be fully thread safe: classes named <something>Name (such as ScopeName, TypeName and others) all have a Name2<something>_t typedef which is either a hash_map or a hash_multimap. These hash maps are accessed through a singleton:

  static Name2<something>_t & s<something>() {

     static Name2<something>_t t;
     return t;

  }

This is troublesome when user code is registering types because hash maps aren't inherently thread safe for writing (correct me if I'm wrong), and because the construction of the static method variable (the singleton implementation) isn't thread safe either. This means that parallel loading of multiple DLLs which have generated _rflx.cpp files compiled in them causes race conditions.

Later access of the registered types is thread safe, though, because the containers are only being read.

Am I wrong? Has any though been put into this? Are there already plans to make this thread safe?

The easiest solution I see is that Intel's Threading Building Blocks has thread safe hash maps, and it's under the GPL with the runtime exception (if I'm not mistaken this is compatible with the LGPL of Reflex).

Thanks,

Jean-François Bastien Received on Wed Jan 23 2008 - 15:33:43 CET

This archive was generated by hypermail 2.2.0 : Thu Jan 24 2008 - 17:50:01 CET