Previous: , Up: Operating System Services   [Contents][Index]


6.4.7.3 Threads

When running more that one SICStus runtime in the same process it is often necessary to protect data with mutual exclusion locks. The following functions implement recursive mutual exclusion locks, which only need static initialization.

SP_mutex_lock()

Locks the mutex.

SP_mutex_unlock()

Unlocks the mutex.

A (recursive) mutual exclusion lock is declared as type SP_mutex. It should be initialized to (the static initializer) SP_MUTEX_INITIALIZER before use.

Note that the SICStus runtime is not thread safe in general.

A dynamic foreign resource that is used by multiple SICStus runtimes in the same process may need to maintain a global state that is kept separate for each SICStus runtime. Each SICStus runtime maintains a location (containing a void*) for each foreign resource. By calling SP_foreign_stash(), a foreign resource can then access this location to store any data that is specific to the calling SICStus runtime.


Send feedback on this subject.