Threading Experts Quiz Question

  • Thread starter Thread starter Tom Jastrzebski
  • Start date Start date
T

Tom Jastrzebski

Here is the scenario:

There are two methods: SetupMethod() and AccessMethod().
1. Only one thread at a time can execute SetupMethod().
2. AccessMethod() can be executed by any number of threads but when
SetupMethod() is executed other threads have to wait.
3. SetupMethod() can not be started when AccessMethod() executes. It needs
to place a lock on AccessMethod() and wait until all other threads are
finish.

How the above can be accomplished?
Tom
 
Tom Jastrzebski said:
Here is the scenario:

There are two methods: SetupMethod() and AccessMethod().
1. Only one thread at a time can execute SetupMethod().
2. AccessMethod() can be executed by any number of threads but when
SetupMethod() is executed other threads have to wait.
3. SetupMethod() can not be started when AccessMethod() executes. It needs
to place a lock on AccessMethod() and wait until all other threads are
finish.

How the above can be accomplished?

Sounds like a ReaderWriterLock does exactly what you need - acquire a
writer lock in SetupMethod and a reader lock in AccessMethod.
 
Back
Top