I have no clue if the thing I want to do has a name or not. The "Master / Slave Lock System", unfortunately, is the best language I could come up with.
Now for the problem I have ...
Imagine you have the following class:
public class Foo
{
public void Master()
{
}
public void Slave1()
{
}
public void Slave2()
{
}
}
I want the slave methods (Slave1, Slave2) to be executed in parallel in a multi-threaded script, but when the master (Master) method is called, the slaves method must be blocked from execution while it is running, additional all the current slave methods must end after the master method is entered .
Something like this (with comments):
public class Foo
{
public void Master()
{
}
public void Slave1()
{
}
public void Slave2()
{
}
}
I know that I can use a lock for all 3 methods, but Slave1 methods will block each other, and this is not what I want.
public class Foo
{
private readonly object _syncLock = new object();
public void Master()
{
lock (_syncLock)
{
}
}
public void Slave1()
{
lock (_syncLock)
{
}
}
public void Slave2()
{
lock (_syncLock)
{
}
}
}
, , - " , ", , .