semaphores??

What is semaphores?, and how do I create them? The man pages are too hard to understand. I'm using C++.

below is the stuff I need to do...I need to understand how to start.... hints?

##################
"Specifically, you will create a set of 4 stand-alone programs, as
follows:

Program #0 - Will always be called first and must create a set of
semaphores. Program #0 must print the exact text "Executing process
#0." when it runs.

Program #1 - Will be called sometime after program #0 and must
adjust the semaphore(s) such that program #2 can run. Program #1
must print the exact text "Executing process #1." when it runs.
Program #1 doesn't do anything else.

Program #2 - Will be called sometime after program #0 and must
adjust the semaphore(s) such that program #3 can run. Program #2
must print the exact text "Executing process #2." when it runs.
Program #2 doesn't do anything else. However, program #2 can only
run AFTER program #1 runs! If program #2 runs before program #1 it
must simply terminate itself.

Program #3 - Will be called sometime after program #0 and should
remove the semaphores from the system. Program #3 must print the
exact text "Executing process #3." when it runs. Program #3
doesn't do anything else. However, program #3 can only
run AFTER program #2 runs! If program #3 runs before program #2 it
must simply terminate itself.
"
#####################

thanx..

Comments

  • A semaphore is an OS level programming construct that allows different processes to coordinate their activities and not stomp on each other.

    For purposes of this exercise, use a simple mechanism first - try a file with a single value as a semaphore simulator. Once you have the basic logic working, try incorporating a true OS based semaphore. The semaphore simulator looks like:

    Have process #1 create the file and write a '1' into it. (option - have it fail if the file already exists!)

    Have process #2 open the file and check if the contents are '1'.
    If it is '1', if it is printf out the execution message and overwrite the file with a '2'.
    If it fails (either because the file does not exist, or the value is not '1'), terminate the process (print out a message to yourself during development).

    Have Process #3 do the same as #2, but check for the value '2', then delete the file.

    Once you have the simulator working, try using a true semaphore (I am not certain of the syntax right off), and set it to various values to indicate what state it is in.

    : What is semaphores?, and how do I create them? The man pages are too hard to understand. I'm using C++.
    :
    : below is the stuff I need to do...I need to understand how to start.... hints?
    :
    : ##################
    : "Specifically, you will create a set of 4 stand-alone programs, as
    : follows:
    :
    : Program #0 - Will always be called first and must create a set of
    : semaphores. Program #0 must print the exact text "Executing process
    : #0." when it runs.
    :
    : Program #1 - Will be called sometime after program #0 and must
    : adjust the semaphore(s) such that program #2 can run. Program #1
    : must print the exact text "Executing process #1." when it runs.
    : Program #1 doesn't do anything else.
    :
    : Program #2 - Will be called sometime after program #0 and must
    : adjust the semaphore(s) such that program #3 can run. Program #2
    : must print the exact text "Executing process #2." when it runs.
    : Program #2 doesn't do anything else. However, program #2 can only
    : run AFTER program #1 runs! If program #2 runs before program #1 it
    : must simply terminate itself.
    :
    : Program #3 - Will be called sometime after program #0 and should
    : remove the semaphores from the system. Program #3 must print the
    : exact text "Executing process #3." when it runs. Program #3
    : doesn't do anything else. However, program #3 can only
    : run AFTER program #2 runs! If program #3 runs before program #2 it
    : must simply terminate itself.
    : "
    : #####################
    :
    : thanx..
    :

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion