in

ASP.NET Weblogs

Carl Franklin

.NET Wonk

SyncLock Demo

I had been fumbling with a good demo for thread synchronization for a while and finally came up with a good demo in VB.NET 2003 illustrating the value of thread synchronization. It calls a sub on three different threads simultaneously. The sub increments a counter in a for/next loop. There are two versions, a raw unsynchronized version and a version that calls SyncLock to synchronize access to the counter.

http://www.franklins.net/dotnet

Published Aug 22 2004, 01:02 AM by Carl Franklin
Filed under:

Comments

 

Marshall Brooke said:

Carl,

There is also the Interlocked.Increment method which takes a reference to an Int32/64 variable and atomically adds 1 to it. I'm not sure about the performance implications over Synclock/lock, but it may perform better for just incrementing an int.

best

Marshall
August 22, 2004 9:30 AM
 

Carl said:

Yes indeed. Good point. It's hard to come up with a good synclock demo that doesn't generate a lot of data
August 22, 2004 10:36 AM

Leave a Comment

(required)  
(optional)
(required)  
Add