互斥体名称-最佳做法? [英] Mutex names - best practice?

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

问题描述

此问题,命名互斥锁的最佳做法是什么?我意识到这可能会随操作系统以及版本(尤其是Windows的版本)而有所不同,因此请在回答时指定平台.我对Win XP和Vista感兴趣.

Related to this question, what is the best practice for naming a mutex? I realize this may vary with OS and even with version (esp for Windows), so please specify platform in answering. My interest is in Win XP and Vista.

推荐答案

全局互斥锁的真正安全名称是<a description> + <a GUID>:

A really safe name for a global mutex is <a description> + <a GUID>:

MyApp Single Instance Mutex : {c96f7db4-d743-4718-bef0-8533a198bcca}

使用这样的名称,绝对没有其他人会使用与您的互斥锁相同的互斥锁名称.

By using a name like this there is absolutely no chance someone else will use the same mutex name as your mutex.

与流程浏览器一起嗅探,您可以看到在一些地方使用了GUID,尽管通常不使用它们.确实出现了一种模式,即互斥"一词被大量使用,微软似乎喜欢使用国会大厦.

Sniffing around with process explorer, you can see that GUIDs are used in a few places, though in general they are not used. A pattern that does emerge though is that the word "mutex" is used quite a lot and Microsoft seem to like using capitols.

这篇关于互斥体名称-最佳做法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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