Next: 2.7.2 Explicit synchronization Up: 2.7 Threads Previous: 2.7 Threads Contents Index

##
2.7.1 Implicit synchronization

Implicit synchronization is a mandatory language feature, since objects such as globaldict are implicitly accessed by the interpreter, which makes it impossible to require the user to explicitly handle all synchronization. Onyx provides optional implicit synchronization capabilities for composite objects on an object by object basis. Each thread has a setting which can be accessed via currentlocking (initially set to false) and set via setlocking . If implicit locking is active, then new objects will be created such that simple accesses are synchronized.

Implicit synchronization can be a source of deadlock, so care must be taken when accessing implicitly locked objects. For example, if two threads copy two implicitly locked strings to the other string, deadlock can result.

    # Initialization.
    $A `aaaaaa'
    $B `bbbbbb'

    ...

    # In thread A:
    A B copy

    ...

    # In thread B:
    B A copy

The following are descriptions of the implicit locking semantics for each type of composite object:

array:
  Array copying is protected. Array element modifications are protected, but element reads are not protected.
class:
  No implicit locking is done for classes.
condition:
  No implicit locking is done for conditions.
dict:
  All dict operations are protected.
file:
  All file operations are protected. There are no potential deadlocks due to implicit file locking.
handle:
  No implicit locking is done for handles.
instance:
  No implicit locking is done for instances.
mutex:
  No implicit locking is done for mutexes.
regex:
  No implicit locking is done for regexes.
regsub:
  No implicit locking is done for regsubs.
stack:
  All stack operations are protected. There are no potential deadlocks due to implicit stack locking. However, there are races in stack copying, such that the results of copying a stack that is concurrently being modified are unpredictable. In addition, removing an object that is being concurrently accessed from a stack is unsafe.
string:
  String copying is protected. Character access is protected by many operators, but string copying is the only potential cause of deadlock for string access.
thread:
  Implicit locking is not done for thread operations, since other synchronization is adequate to protect thread objects.

Next: 2.7.2 Explicit synchronization Up: 2.7 Threads Previous: 2.7 Threads Contents Index