c# - interlock vs mutex, scale-up issues -


I am facing a problem, that I have a C # (.NET) object between some threads. Threads (TCP / IP Connection) can be transformed with others, using the asynchronous framework.

Sequence:

Threads (Waiting for connection) -> Asynchronous Callback -> Some Thread-Safe -> Reach On Shared Object -> Some Thread-Safe

1. Solution Mute X:

  Object Shared Object = New Object (); Mutus object mute x = new mute x (); Zero thread clack () {object object = new object (); // Some Resource objectMutex.lock (); // If necessary, share object with new object // here very little processing objectMutex.unlock (); // some processing}  

embrace 2 solution

  object share object = new object (); SharedObject = 0; Zero thread clack () {object object = new object (); // Some processing // Poll until we are locked (1 ==) while locking. Exchange (Referral using SheareAbject, 1) // If necessary, share the exchange with new object. There is very little processing in Interlock Exchange (rear using ShearAbject, 0); // free lock} // some processing}  

What is fast and what's the better size?

I hope the second solution is not as fast as possible, the second solution for multiple thread polling at the same time can be a random time, so that the time of the voting process is not over. If there is a need to take action on many TCP / IP connections in the past, the first solution is clear to me as I do very little processing in the lock section regarding TCP / IP processing, will there be a staple-up-special ?

How to create an object while initializing the thread () function.

In my C ++ background I always use memory-pool in such a situation, because I have to use safe net is a quick way to create a new object or the .NET platform is good performance in this area Does.

Best regards,

Frederick

second The way it works, the way it appears, if the lock was not achieved, then you are going out, leaving an important part of your code.

Mutex approach is very easy to understand and I did not have any display problem with it.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -