开发者

Request Mutually Exclusive Record

I'm working with C# on two types of applications. One is a web service one is a MVC3 application.

I have the same problem with both. I am trying to create a method that when requested, returns a record for a distributed node to work on.

Concurrency issues cause this to be dangerous. Once process "A" requests a record to work on. If process "B" requests one before the database checks the record for "A" out, they might both get the same record which is bad for this system.

In the webservice I have a web method that is being called "GetRecordToProcess". There is also a corresponding MVC3 ActionResult in a c开发者_如何转开发ontroller that does the same thing.

NOTE the web service and MVC Action DONT need to be mutually exclusive to eachother. They are actually working on two different tables, but I happened to run into the same issue on two separate projects.

I have a working version of this with Mutex but the processes are running my CPU up to almost 60% when i call Mutex.WaitOne which is baaaad. Any suggestions of a light way to do this? This seems obvious that it would be a common distributed computing requirement, I just don't know the common solution.


The back-end needs to be responsible for resolving the concurrency issues. For example, you could create a CheckOut table that keeps track of who has the record currently checked out.

Enhance your web service to have a GetRecordToRead() which returns a read-only version of the record, and TryGetRecordToWrite() which attempts to check out the record (by adding a new check-out record to the CheckOut table) and if it succeeds returns a writeable version of the record

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜