I'm programming an application with severe dependency conditions between three threads. I want to ask you for ADVICE:
I will try to describe my problem: (Thr1, Thr2, Thr3 are semaphores, but I'm thinking about mutex)
the task begins when thread 1 request data from a machine. When it finishes, thread2 begins to receive the data from the machine and storage it in memory. when thread2 is ready thread 3 can begin to read the data from memory and send it to another machine and at the same time thread1 can request for data again. (actually in the middle of thread2 and thread3 there is another application that makes a processing of the data and when it finishes thread3 can read this data and send it)
My first question is a beginner question about semaphore and mutex. A semaphore with the maximum count to 1 is like a mutex? I want to have the maximum count for my semaphore to 1 is it the same for me to use semaphore and mutex? I think I could have problems if I use a semaphore with max count=1 because it could be that when thread2 releases (count +1) thread1 and thread3 are waiting, if thread3 takes the control (wait, count -1) thread1 will wait and doesn't take the control anymore? what is your opinion about this?can you give me some advice?
When I create a semaphore I set the parameter inicial count and with it I can fix what thread begins but with mutex what can I determine what thread begins?
I need to set thread priority too because when thread3 have something to send must be first (thread1 and thread3 communicate with other machine over the same port).
What do you think about this idea?