Hey all. I have an assignment to use a semaphore class with. I'm a little confused by how they work though. [Our teacher speaka no english]
So anywho what we have are 3 Processes that are communicating (a parent and two child processes). Trying to simply the problem basically the two children pass random numbers and their Process Identification Number (PID) to the Parent process via a pipe. Both pieces of data are integers. Basically what we are to use the semaphores for is to have the parent process alternate between the two children as they write to the parent.
For example:
Both children wait for the parent to tell them to write to it (the parent), and the parent alternates between Child1 and Child2; so that the output stream is Child1's data, Child2's data, Child1's data, Child2's data...etc.
I just really need clarification on the what the semaphore does. I know it protects the critical data, but how I am to use it I'm fuzzy on.
I don't know if anyone could just write a line or two of code with a semaphore allowing access to a piece of critical data? I'm familiar with how to declare the semaphore and its member functions, implementation is my weak point.
If you have any good websites or applets that deal with them thats sweet too, I googled but to no avail. The program is being written on a UNIX server. Thanks in advance everyone! :pinch:
Question
Jimmerz28
Hey all. I have an assignment to use a semaphore class with. I'm a little confused by how they work though. [Our teacher speaka no english]
So anywho what we have are 3 Processes that are communicating (a parent and two child processes). Trying to simply the problem basically the two children pass random numbers and their Process Identification Number (PID) to the Parent process via a pipe. Both pieces of data are integers. Basically what we are to use the semaphores for is to have the parent process alternate between the two children as they write to the parent.
For example:
Both children wait for the parent to tell them to write to it (the parent), and the parent alternates between Child1 and Child2; so that the output stream is Child1's data, Child2's data, Child1's data, Child2's data...etc.
I just really need clarification on the what the semaphore does. I know it protects the critical data, but how I am to use it I'm fuzzy on.
I don't know if anyone could just write a line or two of code with a semaphore allowing access to a piece of critical data? I'm familiar with how to declare the semaphore and its member functions, implementation is my weak point.
If you have any good websites or applets that deal with them thats sweet too, I googled but to no avail. The program is being written on a UNIX server. Thanks in advance everyone! :pinch:
Link to comment
Share on other sites
5 answers to this question
Recommended Posts