Please note: this project is inactive since early 2006

 
6.2 Instructions of use in a multi-threaded environment

The framework itself is designed to work in a multi-threaded environment, and it makes sure that critical sections accessing shared variables are correctly handled (such as when the module Database provides or updates the globally cached database snapshots).

However, the EditingContext itself is not MT-safe by default. If your application requires that an EditingContext is concurrently accessed by different threads, you have to make sure that you lock it before use (e.g., before saving changes); methods lock() and unlock() are provided for that purpose. Typical usage follows:

try:
  ec.lock()
  ec.saveChanges()
finally:
  ec.unlock()

Warning: Locking an EditingContext does NOT lock the objects it contains. If you want e.g. to be able to concurrently access & update the objects, you can take different approaches. For example, you might decide to use the EditingContext lock as a global locking mechanism, or you'll design your own locking scheme for your objects.

Last, two nested EditingContext which have the same parent and are managed by two different threads can concurrently save their changes to their parent without explictly locking it -this is managed automatically. This is worth noting, even if this is logical since the framework is supposed to ensure that any operations made on an EditingContext is safe in a multi-threaded environment (given that the EditingContext is not shared between threads, obviously).

Comments are welcome: Sebastien Bigaret / Modeling Home Page
Hosted by:SourceForge.net Logo