Hi,
Firstly please excuse the long ramblingness. I need some conceptual help, I am trying to make two programs that are exactly the same but take it in turns to execute something, so the output looks something like the following:
I have been reading the man pages for semop and semctl and trying to think of a way to make the processes take turns. So far I have implemented one semaphore that each process locks before it does it business and unlocks after. If I force some execution time (sleep(1)) the processes will take turns. If I try with just print statements only one process will execute (presumably it executes fully before the other has a chance to be scheduled).
I had thought of having 2 semaphores that one process locked before processing but the other had to unlock to signal that it was ready to start, but this seems a bit messy. I had also thought about setting and checking semval using the fact that a positive sem_op will increment semval but I am not sure how to go about this?
The coding is fairly straightforward , as far as I can see, I just don't understand how to use the semaphores fully so to achieve this. Any input would be appreciated.
Thanks
David
Firstly please excuse the long ramblingness. I need some conceptual help, I am trying to make two programs that are exactly the same but take it in turns to execute something, so the output looks something like the following:
Code:
setup semaphores, etc . . proc 1 doing first thing proc 2 doing next thing proc 1 doing next thing proc 2 doing next thing proc 1 doing last thing . . shutdown semaphores, etc
I had thought of having 2 semaphores that one process locked before processing but the other had to unlock to signal that it was ready to start, but this seems a bit messy. I had also thought about setting and checking semval using the fact that a positive sem_op will increment semval but I am not sure how to go about this?
The coding is fairly straightforward , as far as I can see, I just don't understand how to use the semaphores fully so to achieve this. Any input would be appreciated.
Thanks
David
Comment