Welcome to Linux Forums! With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.
Write an article for LinuxForums Today! Win Great Prizes!
I am trying out the following piece of code to implement a simple semaphore.
Steps
1. Create Semaphore
2. Initialize it to 1
3. Enter Critical section - SEMAPHORE P Operation
4. >>>> print some numbers >>>>
5. Leave Critical section - SEMAPHORE V Operation
6. Delete Semaphore
Running the program
Execute the program in one terminal.
In another terminal, execute the same program while it is running in terminal 1.
I expect the program in terminal 2 to WAIT for the program in terminal 1 to leave its critical section before it starts running. But this does not happen. Both the programs run simultaneously.
Maybe, my understanding of semaphores is wrong. Could you please point the error in my program?
Open Source Security Myths Dispelled Dispel the five major myths surrounding Open Source Security and gain the tools necessary to make a truly informed decision for your IT organization subscribe
InformationWeek InformationWeek is the only newsweekly you'll need to stay on top of the latest developments in information technology. subscribe