净互斥问题 [英] .Net Mutex Question

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

问题描述

我有一个使用一个互斥为code块的跨进程同步的应用程序。这种机制的伟大工程的应用程序当前的需要。在最坏的情况下,我已经注意到,大约6个线程可以备份互斥。大约需要2-3秒来执行同步code座。

I have an application that uses a Mutex for cross process synchronization of a block of code. This mechanism works great for the applications current needs. In the worst case I have noticed that about 6 threads can backup on the Mutex. It takes about 2-3 seconds to execute the synchronized code block.

我刚刚收到了新的要求,即是要求建立一个优先功能互斥,使得互斥的偶尔有些请求可以被认为是更重要的,然后休息。当这些较高优先级线程之一来在所需的功能是为互斥授予采集到较高优先级请求,而不是降低。

I just received a new requirement that is asking to create a priority feature to the Mutex such that occasionally some requests of the Mutex can be deemed more important then the rest. When one of these higher priority threads comes in the desired functionality is for the Mutex to grant acquisition to the higher priority request instead of the lower.

所以,反正是有控制阻塞互斥队列Windows维护?我应该考虑使用不同的线程模型?

So is there anyway to control the blocked Mutex queue that Windows maintains? Should I consider using a different threading model?

谢谢, 马特

推荐答案

只需使用互斥这将是艰难的一个解决,我相信有人在那里正在考虑线程的优先级等,但我可能不会考虑这条路线

Using just the Mutex this will be tough one to solve, I am sure someone out there is thinking about thread priorities etc. but I would probably not consider this route.

一种选择是保持一个共享存储器结构和实现一个简单的优先级队列。共享内存可以使用MemoryMappedFile,那么当一个进程要执行$ C $的C节它把这个标识与优先级的优先级队列,然后当它唤醒每个线程检查优先级队列,检查的第一个标记在队列中,如果令牌所属的过程中,它可以出队令牌并执行code。

One option would be to maintain a shared memory structure and implement a simple priority queue. The shared memory can use a MemoryMappedFile, then when a process wants to execute the section of code it puts a token with a priority on the priority queue and then when it wakes up each thread inspects the priority queue to check the first token in the queue if the token belongs to the process it can dequeue the token and execute the code.

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

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