什么是互斥? [英] What is a mutex?

查看:314
本文介绍了什么是互斥?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

互斥是一种编程概念,经常用于解决多线程问题。我向社群提出的问题:

A mutex is a programming concept that is frequently used to solve multi-threading problems. My question to the community:

什么是互斥体,您如何使用它?

What is a mutex and how do you use it?

推荐答案

当我在工作中进行热烈的讨论时,我使用一个橡胶鸡,我在我的办公桌上只是在这样的场合。持有鸡的人是唯一被允许谈话的人。如果你不拿鸡,你不能说话。你只能表示你想要的鸡,并等待,直到你得到它之前你说话。一旦你说完,你可以把鸡送回主持人,主持人将把它交给下一个人说话。

When I am having a big heated discussion at work, I use a rubber chicken which I keep in my desk for just such occasions. The person holding the chicken is the only person who is allowed to talk. If you don't hold the chicken you cannot speak. You can only indicate that you want the chicken and wait until you get it before you speak. Once you have finished speaking, you can hand the chicken back to the moderator who will hand it to the next person to speak. This ensures that people do not speak over each other, and also have their own space to talk.

用Mutex替换鸡,用螺纹替换鸡,你基本上有一个概念:互斥体。

Replace Chicken with Mutex and person with thread and you basically have the concept of a mutex.

当然,没有橡皮互斥体这样的东西。只有橡胶鸡。我的猫曾经吃过一只橡皮鸭,但他们吃了。

Of course, there is no such thing as a rubber mutex. Only rubber chicken. My cats once had a rubber mouse, but they ate it.

当然,在使用橡皮鸡之前,你需要问自己,你是否真的需要5个人一个房间,它不会只是更容易与一个人在房间里自己做所有的工作。其实,这只是扩展类比,但你得到的想法。

Of course, before you use the rubber chicken, you need to ask yourself whether you actually need 5 people in one room and would it not just be easier with one person in the room on their own doing all the work. Actually, this is just extending the analogy, but you get the idea.

这篇关于什么是互斥?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆