HALCON Reference Manual 10.0.2
Table of Contents / System / Multithreading ClassesClassesClasses | | | Operators

create_mutexcreate_mutexcreate_mutexCreateMutexCreateMutex (Operator)

Name

create_mutexcreate_mutexcreate_mutexCreateMutexCreateMutex — Create a mutual exclusion synchronization object.

Signature

create_mutex( : : AttribName, AttribValue : MutexHandle)

Herror create_mutex(const char* AttribName, const char* AttribValue, Hlong* MutexHandle)

Herror T_create_mutex(const Htuple AttribName, const Htuple AttribValue, Htuple* MutexHandle)

Herror create_mutex(const HTuple& AttribName, const HTuple& AttribValue, Hlong* MutexHandle)

void HMutex::CreateMutex(const HTuple& AttribName, const HTuple& AttribValue)

void HOperatorSetX.CreateMutex(
[in] VARIANT AttribName, [in] VARIANT AttribValue, [out] VARIANT* MutexHandle)

void HMutexX.CreateMutex(
[in] VARIANT AttribName, [in] VARIANT AttribValue)

static void HOperatorSet.CreateMutex(HTuple attribName, HTuple attribValue, out HTuple mutexHandle)

public HMutex(HTuple attribName, HTuple attribValue)

public HMutex(string attribName, string attribValue)

void HMutex.CreateMutex(HTuple attribName, HTuple attribValue)

void HMutex.CreateMutex(string attribName, string attribValue)

Description

A mutex is a synchronization object that negotiates mutual exclusion among threads of a single process to avoid simultaneous modifications on common resources such as global variables. A mutex has two possible states: unlocked, i.e., not owned by any thread, and locked, i.e., owned by one certain thread. Threads attempting to lock a mutex that is already owned by another thread, i.e., locked, wait until the owning thread unlocks the mutex first. Unlike events, a thread has to own a mutex to unlock it.

create_mutexcreate_mutexcreate_mutexCreateMutexCreateMutex allocates and initializes the mutex object according to the attributes specified in AttribNameAttribNameAttribNameAttribNameattribName and AttribValueAttribValueAttribValueAttribValueattribValue. AttribNameAttribNameAttribNameAttribNameattribName specifies the attribute class and AttribValueAttribValueAttribValueAttribValueattribValue the kind of the mutex. The description beneath lists all mutex kinds supported by following classes:

Valref(”)

empty string sets the default attributes.

Valref('type')

specifies what happens if a thread attempts to lock a mutex that is already owned:

'sleep'"sleep""sleep""sleep""sleep"

simply suspends the calling thread (default). The behavior is undefined, if the thread is already owner of the mutex.

'spin'"spin""spin""spin""spin"

a fast mutex implementation that is busy waiting for the signaled mutex. The behavior is undefined, if the thread is already owner of the mutex.

'recursive'"recursive""recursive""recursive""recursive"

suspends the calling thread if the thread is not owner of the mutex. But a recursive mutex can be acquired again by the owning thread. A recursive mutex does not become unlocked until the number of unlock requests equals the number of successful lock requests.

The mutex is unlocked when created.

Parallelization

Parameters

AttribNameAttribNameAttribNameAttribNameattribName (input_control)  number(-array) HTupleHTupleVARIANTHtuple (string / integer / real) (string / int / long / double) (char* / Hlong / double) (BSTR / Hlong / double) (char* / Hlong / double)

Mutex attribute class.

Default value: '' "" "" "" ""

List of values: ''"""""""", 'type'"type""type""type""type"

AttribValueAttribValueAttribValueAttribValueattribValue (input_control)  number(-array) HTupleHTupleVARIANTHtuple (string / integer / real) (string / int / long / double) (char* / Hlong / double) (BSTR / Hlong / double) (char* / Hlong / double)

Mutex attribute kind.

Number of elements: AttribValue == AttribName

Default value: '' "" "" "" ""

List of values: ''"""""""", 'spin'"spin""spin""spin""spin", 'sleep'"sleep""sleep""sleep""sleep", 'recursive'"recursive""recursive""recursive""recursive"

MutexHandleMutexHandleMutexHandleMutexHandlemutexHandle (output_control)  mutex HMutex, HTupleHMutex, HTupleHMutexX, VARIANTHtuple (integer) (IntPtr) (Hlong) (Hlong) (Hlong)

Mutex synchronization object.

Result

create_mutexcreate_mutexcreate_mutexCreateMutexCreateMutex returns 2 (H_MSG_TRUE) if all parameters are correct. If necessary, an exception is raised.

Possible Successors

lock_mutexlock_mutexlock_mutexLockMutexLockMutex, clear_mutexclear_mutexclear_mutexClearMutexClearMutex

See also

clear_mutexclear_mutexclear_mutexClearMutexClearMutex

Module

Foundation


Table of Contents / System / Multithreading ClassesClassesClasses | | | Operators
HALCON Reference Manual 10.0.2 Copyright © 1996-2011 MVTec Software GmbH