Skip to main content
GameDev.net gamedev.net
🔒 Locked

c# Thread locking

Started by ziplock9000 May 28, 2008 at 12:42 AM 1 replies 750+ views
Original Post
ziplock9000
ziplock9000
I've been trying to get my head around thread locking and using lock(ddd) { } to no avail.. Here is the scenario (psudocode) class Foo { function moo { ..somecode ..somecode } } I have multiple instances of the class above. The moo method in each instance will be called on separate threads. It's possible that they will be called at the same time and will overlap. This is the problem, I want it so that only once instance at a time can have its the moo function called. I've tried wrapping the contents of moo up with lock(this), etc, and it does not work. Help please!
"Go bone a model!"
Spodi
Spodi
Use a static object and lock that:

class Foo{   static object lockObj = new object();   function moo {      lock (lockObj) {         ...somecode...      }   }}
NetGore - Open source multiplayer RPG engine
ziplock9000
ziplock9000
thanks, I'll give that a shot
"Go bone a model!"

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.