c# - Locking hierarchy of objects in .NET -


I have a class that represents "the state of the world" There are many collections of many other objects in the class Which in turn is in reference to the collection of more objects and objects, sometimes in reference to their ancestors in the "world hierarchy". To simplify what is being said, here is an example (has been changed to XML, details details):

   

Two threads, UI threads and background threads (which is actually a server).

The server receives the message "Junk" (adding cities, blocks, etc.).

UI thread drages the world's state in a while using the picture box object. The reference layer only refers to the IWorld object (which applies to the world), and there is no way to access the elements inside it.

UI threads should lock the world's Full position so that the world can not be changed during the drawing (which creates a picture of an incompatible world). Since its only reference to the IWorld object, this is the only thing to be locked.

My question is whether this lock will be sufficient (that is, lock all the fields and this object is locked in an inconsistent state), or each object should be locked separately. What is the correct view of this problem?

Note: UI has no way to contact the server (which means it can not tell the server to stop changing the world, and then tell it < / P>

Edit : If all the classes in the world and Hiraach implement the ILOK interface which provides the lock () method which calls the lock () at all low levels ( Again), it may possibly be deadlock (cyclical reference) or simply flowing

I think the design change is in order.

You do not need to lock the recursive - if both threads lock on the same IWorld context, then be sufficient to reassure mutual specification.

Locking on different elements will definitely give you better locking, but then you can end up with an incompatible figure - I call

However, a better model usually publishes "snapshots" to the server and then a new copy of the world. To create and modify the copy, when appropriate, by changing the snapshot you do not need this exclusional exclusion which can block your UI when the server is changing it, while the Turning it up is changing.


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -