About: Global Lock |
01 | When interacting with or acting within the Semys Library, very often a 'Global Lock' state has to be ensured. |
02 | The Semys Library is built on an asynchronous design. The using code of the library must be allowed to access the library by several threads and the library itself runs several threads internally. |
03 | The only threads that the Semys Library runs internally are those of the transporter - where the transportation interfaces have to be monitored on an event driven basis. |
04 | But except for the transporter (and timeout handler), everything else within the library has nothing to do by itself. Either the transporter interface received new data or the user requests an action - but both events have a direct effect on the other side. |
05 |
Placing each part in the chain between transporter and user into a dedicated thread
and adding clean data passing procedures would cause a loss of performance: Managment data would either needed to be dynamically allocated or monitored. Furthermore a constant thread switching would happen sequentially for nearly the same data that hardly becomes modified. |
06 | So, by using as few threads as possible in the Semys Library, many parts within the library will be accessed (modified) from different threads simultaneously. |
07 | To ensure safe access to the data within the library from all threads, one global mutex object is maintained. |
08 |
Using several mutex objects (one for each part in the chain of call stack) in this
environment would be very prone to dead locks. The initial implementation of the Semys Library used several mutex objects and failed to work because of this problem. |
09 | Functions of the Semys Library that require a locked context have the suffix 'Prot' in their name. The caller either has to be within a locked context already or ensure the global mutex object is locked. |
10 | Every callback from the Semys Library is within the context of the global lock. |
11 | Actions within a callback either result in other calls that require a locked context or end up at the user that either uses protected calls as well or switches to asynchronous notification (messaging). |
Goto: Main Page; This page is part of the Semys software documentation. See About: Documentation for details. |