Multithreading Doubt in C#

Asked

Viewed 142 times

1

I have the following scenario: Three types of threads can be created in the program, imagine they are, A, B and C. I have to respect the following rule:

A thread C not can access the critical region if there is already one or more threads B running and vice versa. (A threads can run regardless of how many or which others are also running)

My question is: What is the most efficient way to implement it in C#?

  • What do you mean critical region? Are you referring to a shared variable?

  • What is the difference between threads A and B? By Description, it seems to me that both can run the critical region without restrictions.

  • The problem is an adaptation of the Unisex Bathroom Problem by my teacher. Suppose threads of type C are men and B women. They can run the critical region, but never at the same time.

1 answer

3


When you fire Thread C check that Thread B is running using the property:

Thread.IsAlive

If false performs Thread C procedures.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.