In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "what are the differences between semaphores and mutexes under linux". The explanation in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what are the differences between semaphores and mutexes under linux".
The differences between semaphores and mutexes under linux are: 1, semaphores are used for multithreading and multitask synchronization, while mutexes are used for multithreading and multitasking mutual exclusion; 2, semaphores can allow other threads to do certain actions when one thread completes an action, while the mutex thread once occupies a certain resource, other threads cannot access it.
The operating environment of this tutorial: linux7.3 system, Dell G3 computer.
What is the difference between semaphores and mutexes in linux
Semaphores (semaphore [sem synchronization f: (r)]) are used in multi-thread and multi-task synchronization. When a thread completes an action, it tells other threads through the semaphore, and then other threads take certain actions.
The Mutual exclusion (Mutex) is used for multithreading and multitask mutual exclusion. If a thread occupies a resource, other threads cannot access it until this thread unlock, and other threads can not use this resource.
For example, the access to global variables is sometimes locked and unlocked when the operation is finished. Although the two concepts are somewhat similar, their focus is different. Semaphores are not necessarily locking a resource, but a process concept.
For example: there are two threads A _ thread A _
Thread mutex is the concept of "locking a resource". During the locking period, other threads cannot operate on the protected data.
It is not difficult to see that mutex is a special case of semaphore.
In other words, the latter can be used instead of the former. However, because mutex is simple and efficient, this design is adopted when it is necessary to ensure the exclusive use of resources.
Thank you for your reading, the above is the content of "what is the difference between semaphores and mutex locks under linux". After the study of this article, I believe you have a deeper understanding of the difference between semaphores and mutex locks under linux, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.