Multi-thread synchronization mutex (functionally the same as critial sections, but is a kernel object with slow access and can be called by different processes)
A Mutex
A mutex object (mutex) kernel object ensures that the thread has exclusive access to a single resource. In fact, the mutex object is therefore named. A mutex object contains a usage quantity, a thread ID, and a recursive counter.
The mutex object behaves the same as the key code snippet, but the mutex object belongs to the kernel object, and the critical code fragment belongs to the user mode object. This means that the mutex object is running slower than the critical code segment. However, this also means that multiple threads in different processes can access a single mutex, and this means that the thread can set a timeout value while waiting for access to the resource.
The ID is used to identify which thread in the system currently has a mutex, and the recursive counter is used to indicate the number of times that the thread has a mutex.
Mutex objects have many uses and belong to one of the most commonly used kernel objects. Typically, they are used to protect blocks of memory accessed by multiple threads. If multiple threads are accessing memory blocks at the same time, the data in the memory block can be compromised. A mutex ensures that any thread that accesses a block of memory has exclusive access to that block of memory, which guarantees the integrity of the data.
/****************************************************************************** OpenST Basic Tool Library * * Copyright (C) Henry.wen [email protected]. * * * * This file was part of OST. * * * This program was free software; You can redistribute it and/or modify * * it under the terms of the GNU general public License version 3 as * * Published by the free software Foundation. * * * You should has received a copy of the G NU general public License * * along with OST. If not, see
Ostmutex_posix.cpp/****************************************************************************** OpenST Basic Tool Library * * Copyright (C) Henry.wen [email protected]. * * * * This file was part of OST. * * * This program was free software; You can redistribute it and/or modify * * it under the terms of the GNU general public License version 3 as * * Published by the free software Foundation. * * * You should has received a copy of the G NU general public License * * along with OST. If not, see
Ostmutex_win32.cpp/****************************************************************************** OpenST Basic Tool Library * * Copyright (C) Henry.wen [email protected]. * * * * This file was part of OST. * * * This program was free software; You can redistribute it and/or modify * * it under the terms of the GNU general public License version 3 as * * Published by the free software Foundation. * * * You should has received a copy of the G NU general public License * * along with OST. If not, see
Multi-threaded Mutex--mutex