Monday, August 6, 2007

Critical Section in C#

Here is a good article on using the lock statement to create critical sections in C#:

http://www.calcaria.net/c-sharp/2006/10/c-equivalent-csinglelock-critical.html

Here is the gist:

Object lockobj = new Object();

lock (lockobj)
{
// Do your locked work
}

2 comments:

Anonymous said...

Another noteworthy article
http://www.discretevector.com/2008/02/locks-threads-and-this-huh-most-people.html

Elton Beach said...

Locking on this is bad though because some other line could conceivably
lock on this developing a state of chaos of types. But that provides you with roughly the comparative of a crucial area.