create_mutexT_create_mutexCreateMutexCreateMutexcreate_mutex (算子)
名称
create_mutexT_create_mutexCreateMutexCreateMutexcreate_mutex — 创建互斥同步对象。
签名
void CreateMutex(const HTuple& AttribName, const HTuple& AttribValue, HTuple* MutexHandle)
void HMutex::HMutex(const HTuple& AttribName, const HTuple& AttribValue)
void HMutex::HMutex(const HString& AttribName, const HString& AttribValue)
void HMutex::HMutex(const char* AttribName, const char* AttribValue)
void HMutex::HMutex(const wchar_t* AttribName, const wchar_t* AttribValue)
(
Windows only)
void HMutex::CreateMutex(const HTuple& AttribName, const HTuple& AttribValue)
void HMutex::CreateMutex(const HString& AttribName, const HString& AttribValue)
void HMutex::CreateMutex(const char* AttribName, const char* AttribValue)
void HMutex::CreateMutex(const wchar_t* AttribName, const wchar_t* AttribValue)
(
Windows only)
def create_mutex(attrib_name: MaybeSequence[Union[int, float, str]], attrib_value: MaybeSequence[Union[int, float, str]]) -> HHandle
描述
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_mutexCreateMutexCreateMutexCreateMutexcreate_mutex allocates and initializes the mutex object according to
the attributes specified in AttribNameAttribNameAttribNameAttribNameattribNameattrib_name and AttribValueAttribValueAttribValueAttribValueattribValueattrib_value.
AttribNameAttribNameAttribNameAttribNameattribNameattrib_name specifies the attribute class and AttribValueAttribValueAttribValueAttribValueattribValueattrib_value
the kind of the mutex. The description beneath lists all mutex kinds
supported by following classes:
- ''""""""""""
empty string sets the default attributes.
- 'type'"type""type""type""type""type"
-
specifies what happens if a thread attempts to lock a
mutex that is already owned:
- 'sleep'"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""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""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.
执行信息
- 多线程类型:独立(即使使用独占算子也能并行运行)。
- 多线程作用域:全局(可从任何线程调用)。
- 未采用并行化处理。
参数
AttribNameAttribNameAttribNameAttribNameattribNameattrib_name (输入控制) number(-array) → HTupleMaybeSequence[Union[int, float, str]]HTupleHtuple (string / integer / real) (string / int / long / double) (HString / Hlong / double) (char* / Hlong / double)
Mutex attribute class.
默认值:
[]
值列表:
'type'"type""type""type""type""type"
AttribValueAttribValueAttribValueAttribValueattribValueattrib_value (输入控制) number(-array) → HTupleMaybeSequence[Union[int, float, str]]HTupleHtuple (string / integer / real) (string / int / long / double) (HString / Hlong / double) (char* / Hlong / double)
Mutex attribute kind.
元素数量:
AttribValue == AttribName
默认值:
[]
值列表:
'recursive'"recursive""recursive""recursive""recursive""recursive", 'sleep'"sleep""sleep""sleep""sleep""sleep", 'spin'"spin""spin""spin""spin""spin"
MutexHandleMutexHandleMutexHandleMutexHandlemutexHandlemutex_handle (输出控制) mutex → HMutex, HTupleHHandleHTupleHtuple (handle) (IntPtr) (HHandle) (handle)
Mutex synchronization object.
结果
create_mutexcreate_mutexCreateMutexCreateMutexCreateMutexcreate_mutex 在所有参数正确时返回 2 ( H_MSG_TRUE )。如有必要,则抛出异常。
可能的后继
lock_mutexlock_mutexLockMutexLockMutexLockMutexlock_mutex,
clear_mutexclear_mutexClearMutexClearMutexClearMutexclear_mutex
另见
clear_mutexclear_mutexClearMutexClearMutexClearMutexclear_mutex
模块
基础