Click to See Complete Forum and Search --> : Synchronization:Blocking one function if other is running


laserwave
May 13th, 2009, 01:33 AM
Hello All,
I have three functions f1(),f2(),f3()

if I enter in
f1()
{


}
f2() and f3() should blocked till f1() executes completley
f2()
{
lock

unlock
}

f3()
{
lock

unlock
}


I tried EnterCritical section but not on mark.
What would be best way to achieve it ? I don't want to use global

MrViggy
May 13th, 2009, 01:06 PM
Well, if you want F2 and F3 to block when F1 is running, you will need some kind of "global" lock that all three can access. Instead of a global variable, just use a singleton. The easiest way would be to create a class that wraps a critical section, but either make all members of the class static, or create a single static function in the class that always returns the same object. Do a search for the "singleton pattern."

Viggy

Feered
May 15th, 2009, 06:40 PM
If I understand what your saying, why don't you just have the functions run on the same thread instead of them all operating on a different thread?