Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Synchronization using Semaphores

Synchronization using Semaphores

Scheduled Pinned Locked Moved The Lounge
lounge
11 Posts 10 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    toni kukuoc
    wrote on last edited by
    #1

    A particular river crossing is shared by both cannibals and missionaries. A boat is used to cross the river but it only seats three people and must always carry a full load. In order to guarantee the safety of the missionaries, you can not put one missionary and two cannibals into the same boat (because cannibals would gang up and eat that single missionary), but all other combinations are legal. Your program will first ask the number of missionaries and cannibals. The number of cannibals must be greater than one, and the number of missionaries must be greater than two, finally the total number of persons should be multiples of three. First, you should create processes for each cannibal and missionaries. They will walk to the river bank for a while (arrival times are random, you can use sleep call here). Two procedures are needed, Missionary_Arrived and Cannibal_Arrived called by missionary or cannibal processes when they arrive the river bank. These procedures are responsible for synchronization. And these procedures arrange arriving missionaries and cannibals into safe boatloads. Once the boat is full, one process calls Raw_Boat and after calling Row_Boat, the three procedures then return. Then a new boat arrives. There should also be no undue waiting; that is missionaries and cannibals should not wait if there are enough of them for a safe boatload. Your program should display how a boat is arranged each time and who is on the boat. If there are any persons left at the end of your program, they must be reported. Remember that, all the synchronization operations should be mutually exclusive. You must use UNIX semaphores to enable synchronization. codingggggggggggggggggggg

    PJ ArendsP R S M V 6 Replies Last reply
    0
    • T toni kukuoc

      A particular river crossing is shared by both cannibals and missionaries. A boat is used to cross the river but it only seats three people and must always carry a full load. In order to guarantee the safety of the missionaries, you can not put one missionary and two cannibals into the same boat (because cannibals would gang up and eat that single missionary), but all other combinations are legal. Your program will first ask the number of missionaries and cannibals. The number of cannibals must be greater than one, and the number of missionaries must be greater than two, finally the total number of persons should be multiples of three. First, you should create processes for each cannibal and missionaries. They will walk to the river bank for a while (arrival times are random, you can use sleep call here). Two procedures are needed, Missionary_Arrived and Cannibal_Arrived called by missionary or cannibal processes when they arrive the river bank. These procedures are responsible for synchronization. And these procedures arrange arriving missionaries and cannibals into safe boatloads. Once the boat is full, one process calls Raw_Boat and after calling Row_Boat, the three procedures then return. Then a new boat arrives. There should also be no undue waiting; that is missionaries and cannibals should not wait if there are enough of them for a safe boatload. Your program should display how a boat is arranged each time and who is on the boat. If there are any persons left at the end of your program, they must be reported. Remember that, all the synchronization operations should be mutually exclusive. You must use UNIX semaphores to enable synchronization. codingggggggggggggggggggg

      PJ ArendsP Offline
      PJ ArendsP Offline
      PJ Arends
      wrote on last edited by
      #2

      kewl:-D Hope you have fun with your homework;) ps. Wrong forum


      "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!

      Within you lies the power for good; Use it!

      1 Reply Last reply
      0
      • T toni kukuoc

        A particular river crossing is shared by both cannibals and missionaries. A boat is used to cross the river but it only seats three people and must always carry a full load. In order to guarantee the safety of the missionaries, you can not put one missionary and two cannibals into the same boat (because cannibals would gang up and eat that single missionary), but all other combinations are legal. Your program will first ask the number of missionaries and cannibals. The number of cannibals must be greater than one, and the number of missionaries must be greater than two, finally the total number of persons should be multiples of three. First, you should create processes for each cannibal and missionaries. They will walk to the river bank for a while (arrival times are random, you can use sleep call here). Two procedures are needed, Missionary_Arrived and Cannibal_Arrived called by missionary or cannibal processes when they arrive the river bank. These procedures are responsible for synchronization. And these procedures arrange arriving missionaries and cannibals into safe boatloads. Once the boat is full, one process calls Raw_Boat and after calling Row_Boat, the three procedures then return. Then a new boat arrives. There should also be no undue waiting; that is missionaries and cannibals should not wait if there are enough of them for a safe boatload. Your program should display how a boat is arranged each time and who is on the boat. If there are any persons left at the end of your program, they must be reported. Remember that, all the synchronization operations should be mutually exclusive. You must use UNIX semaphores to enable synchronization. codingggggggggggggggggggg

        R Offline
        R Offline
        Roger Wright
        wrote on last edited by
        #3

        :-D Sounds like a fun homework assignment! Be sure to post your finished project as an article here so that we all can learn from it.;) "If it's Snowbird season, why can't we shoot them?" - Overheard in a bar in Bullhead City

        1 Reply Last reply
        0
        • T toni kukuoc

          A particular river crossing is shared by both cannibals and missionaries. A boat is used to cross the river but it only seats three people and must always carry a full load. In order to guarantee the safety of the missionaries, you can not put one missionary and two cannibals into the same boat (because cannibals would gang up and eat that single missionary), but all other combinations are legal. Your program will first ask the number of missionaries and cannibals. The number of cannibals must be greater than one, and the number of missionaries must be greater than two, finally the total number of persons should be multiples of three. First, you should create processes for each cannibal and missionaries. They will walk to the river bank for a while (arrival times are random, you can use sleep call here). Two procedures are needed, Missionary_Arrived and Cannibal_Arrived called by missionary or cannibal processes when they arrive the river bank. These procedures are responsible for synchronization. And these procedures arrange arriving missionaries and cannibals into safe boatloads. Once the boat is full, one process calls Raw_Boat and after calling Row_Boat, the three procedures then return. Then a new boat arrives. There should also be no undue waiting; that is missionaries and cannibals should not wait if there are enough of them for a safe boatload. Your program should display how a boat is arranged each time and who is on the boat. If there are any persons left at the end of your program, they must be reported. Remember that, all the synchronization operations should be mutually exclusive. You must use UNIX semaphores to enable synchronization. codingggggggggggggggggggg

          S Offline
          S Offline
          Simon Brown
          wrote on last edited by
          #4

          Just leave the missionaries with the cannibals and maybe we'll all have a better life without all these god botherers. Old Simon HB9DRV

          1 Reply Last reply
          0
          • T toni kukuoc

            A particular river crossing is shared by both cannibals and missionaries. A boat is used to cross the river but it only seats three people and must always carry a full load. In order to guarantee the safety of the missionaries, you can not put one missionary and two cannibals into the same boat (because cannibals would gang up and eat that single missionary), but all other combinations are legal. Your program will first ask the number of missionaries and cannibals. The number of cannibals must be greater than one, and the number of missionaries must be greater than two, finally the total number of persons should be multiples of three. First, you should create processes for each cannibal and missionaries. They will walk to the river bank for a while (arrival times are random, you can use sleep call here). Two procedures are needed, Missionary_Arrived and Cannibal_Arrived called by missionary or cannibal processes when they arrive the river bank. These procedures are responsible for synchronization. And these procedures arrange arriving missionaries and cannibals into safe boatloads. Once the boat is full, one process calls Raw_Boat and after calling Row_Boat, the three procedures then return. Then a new boat arrives. There should also be no undue waiting; that is missionaries and cannibals should not wait if there are enough of them for a safe boatload. Your program should display how a boat is arranged each time and who is on the boat. If there are any persons left at the end of your program, they must be reported. Remember that, all the synchronization operations should be mutually exclusive. You must use UNIX semaphores to enable synchronization. codingggggggggggggggggggg

            M Offline
            M Offline
            Marc Clifton
            wrote on last edited by
            #5

            What I love about these homework assignments is that they're so subject to interpretation it's impossible to figure out. Take "Missionary_Arrived". Now, this method appears to do several things: 1. responsible for synchronization 2. arrange arriving missionaries 3. and these procedures (Missionary_Arrived and Cannibal_Arrived) arrange arriving missionaries and cannibals into safe boatloads Now, I ask you, does arriving missionaries mean arriving at the departure boat or arriving at the other side of the river? I'm sooo confused!!! Then it says: toni kukuoc wrote: Then a new boat arrives Is this an empty boat, ready to take on missionaries and cannibals, or is this a boat full of said people? And exactly how many boats are on this river??? Since there's no upper limit on the number of cannibals and missionaries, eventually it seems that the river would get choked up with boats!!! Certainly the instructions give NO CLUE as to how boats depart. Only arrive. So, in the end, the missionaries and cannibals should just be able to walk across the river, going from boat to boat. But to figure this out, we need to know more information about the river, it's width, the current, the size of each boat, etc. These are not input parameters! And finally: toni kukuoc wrote: If there are any persons left at the end of your program, they must be reported. How dumb is that! The parameters are clear: (M+A)/3 must not have a remainder. And each boat must be full. IT'S IMPOSSIBLE TO HAVE PERSONS LEFT AT THE END OF THE PROGRAM!!! Who should they be reported to? The missing person's bureau? The only way I figure there can be persons left at the end is if the missionaries succeed in converting some of the cannibals to missionaries while waiting for a boat! Gads, with idiotic assignments like this that make no sense, no wonder I couldn't deal with programming classes. Marc MyXaml Advanced Unit Testing

            C T 2 Replies Last reply
            0
            • M Marc Clifton

              What I love about these homework assignments is that they're so subject to interpretation it's impossible to figure out. Take "Missionary_Arrived". Now, this method appears to do several things: 1. responsible for synchronization 2. arrange arriving missionaries 3. and these procedures (Missionary_Arrived and Cannibal_Arrived) arrange arriving missionaries and cannibals into safe boatloads Now, I ask you, does arriving missionaries mean arriving at the departure boat or arriving at the other side of the river? I'm sooo confused!!! Then it says: toni kukuoc wrote: Then a new boat arrives Is this an empty boat, ready to take on missionaries and cannibals, or is this a boat full of said people? And exactly how many boats are on this river??? Since there's no upper limit on the number of cannibals and missionaries, eventually it seems that the river would get choked up with boats!!! Certainly the instructions give NO CLUE as to how boats depart. Only arrive. So, in the end, the missionaries and cannibals should just be able to walk across the river, going from boat to boat. But to figure this out, we need to know more information about the river, it's width, the current, the size of each boat, etc. These are not input parameters! And finally: toni kukuoc wrote: If there are any persons left at the end of your program, they must be reported. How dumb is that! The parameters are clear: (M+A)/3 must not have a remainder. And each boat must be full. IT'S IMPOSSIBLE TO HAVE PERSONS LEFT AT THE END OF THE PROGRAM!!! Who should they be reported to? The missing person's bureau? The only way I figure there can be persons left at the end is if the missionaries succeed in converting some of the cannibals to missionaries while waiting for a boat! Gads, with idiotic assignments like this that make no sense, no wonder I couldn't deal with programming classes. Marc MyXaml Advanced Unit Testing

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              My programming teacher was useless in other ways. He'd set the most basic assignments, then come and ask me how I'd done them ( I'd be playing Star Trek by the time he finished explaining it ), because he had no idea. I dropped out of that course. Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer

              1 Reply Last reply
              0
              • T toni kukuoc

                A particular river crossing is shared by both cannibals and missionaries. A boat is used to cross the river but it only seats three people and must always carry a full load. In order to guarantee the safety of the missionaries, you can not put one missionary and two cannibals into the same boat (because cannibals would gang up and eat that single missionary), but all other combinations are legal. Your program will first ask the number of missionaries and cannibals. The number of cannibals must be greater than one, and the number of missionaries must be greater than two, finally the total number of persons should be multiples of three. First, you should create processes for each cannibal and missionaries. They will walk to the river bank for a while (arrival times are random, you can use sleep call here). Two procedures are needed, Missionary_Arrived and Cannibal_Arrived called by missionary or cannibal processes when they arrive the river bank. These procedures are responsible for synchronization. And these procedures arrange arriving missionaries and cannibals into safe boatloads. Once the boat is full, one process calls Raw_Boat and after calling Row_Boat, the three procedures then return. Then a new boat arrives. There should also be no undue waiting; that is missionaries and cannibals should not wait if there are enough of them for a safe boatload. Your program should display how a boat is arranged each time and who is on the boat. If there are any persons left at the end of your program, they must be reported. Remember that, all the synchronization operations should be mutually exclusive. You must use UNIX semaphores to enable synchronization. codingggggggggggggggggggg

                V Offline
                V Offline
                Vivi Chellappa
                wrote on last edited by
                #7

                toni kukuoc wrote: In order to guarantee the safety of the missionaries, you can not put one missionary and two cannibals into the same boat (because cannibals would gang up and eat that single missionary), but all other combinations are legal. Can we reverse the cultural bias against cannibals by changing the above statement to: "In order to guarantee the culture of the cannibals, you cannot put one cannibal and two missionaries into the same boat (because missionaries would gang up and convert that single cannibal), but all other combinations are legal"? ;P

                A 1 Reply Last reply
                0
                • T toni kukuoc

                  A particular river crossing is shared by both cannibals and missionaries. A boat is used to cross the river but it only seats three people and must always carry a full load. In order to guarantee the safety of the missionaries, you can not put one missionary and two cannibals into the same boat (because cannibals would gang up and eat that single missionary), but all other combinations are legal. Your program will first ask the number of missionaries and cannibals. The number of cannibals must be greater than one, and the number of missionaries must be greater than two, finally the total number of persons should be multiples of three. First, you should create processes for each cannibal and missionaries. They will walk to the river bank for a while (arrival times are random, you can use sleep call here). Two procedures are needed, Missionary_Arrived and Cannibal_Arrived called by missionary or cannibal processes when they arrive the river bank. These procedures are responsible for synchronization. And these procedures arrange arriving missionaries and cannibals into safe boatloads. Once the boat is full, one process calls Raw_Boat and after calling Row_Boat, the three procedures then return. Then a new boat arrives. There should also be no undue waiting; that is missionaries and cannibals should not wait if there are enough of them for a safe boatload. Your program should display how a boat is arranged each time and who is on the boat. If there are any persons left at the end of your program, they must be reported. Remember that, all the synchronization operations should be mutually exclusive. You must use UNIX semaphores to enable synchronization. codingggggggggggggggggggg

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  im sure you will need a method called Missionary_Position somewhere in there

                  R 1 Reply Last reply
                  0
                  • V Vivi Chellappa

                    toni kukuoc wrote: In order to guarantee the safety of the missionaries, you can not put one missionary and two cannibals into the same boat (because cannibals would gang up and eat that single missionary), but all other combinations are legal. Can we reverse the cultural bias against cannibals by changing the above statement to: "In order to guarantee the culture of the cannibals, you cannot put one cannibal and two missionaries into the same boat (because missionaries would gang up and convert that single cannibal), but all other combinations are legal"? ;P

                    A Offline
                    A Offline
                    Aamir Butt
                    wrote on last edited by
                    #9

                    Will two Missionaries be enough for a Cannibal :confused:


                    Stuck to Programming through an unbreakable bond :( My Articles


                    1 Reply Last reply
                    0
                    • L Lost User

                      im sure you will need a method called Missionary_Position somewhere in there

                      R Offline
                      R Offline
                      Richard Jones
                      wrote on last edited by
                      #10

                      Josh Gray wrote: im sure you will need a method called Missionary_Position somewhere in there ah beying ma ung;P Mine is not to question Why, but to shake my head and sigh.:sigh:

                      1 Reply Last reply
                      0
                      • M Marc Clifton

                        What I love about these homework assignments is that they're so subject to interpretation it's impossible to figure out. Take "Missionary_Arrived". Now, this method appears to do several things: 1. responsible for synchronization 2. arrange arriving missionaries 3. and these procedures (Missionary_Arrived and Cannibal_Arrived) arrange arriving missionaries and cannibals into safe boatloads Now, I ask you, does arriving missionaries mean arriving at the departure boat or arriving at the other side of the river? I'm sooo confused!!! Then it says: toni kukuoc wrote: Then a new boat arrives Is this an empty boat, ready to take on missionaries and cannibals, or is this a boat full of said people? And exactly how many boats are on this river??? Since there's no upper limit on the number of cannibals and missionaries, eventually it seems that the river would get choked up with boats!!! Certainly the instructions give NO CLUE as to how boats depart. Only arrive. So, in the end, the missionaries and cannibals should just be able to walk across the river, going from boat to boat. But to figure this out, we need to know more information about the river, it's width, the current, the size of each boat, etc. These are not input parameters! And finally: toni kukuoc wrote: If there are any persons left at the end of your program, they must be reported. How dumb is that! The parameters are clear: (M+A)/3 must not have a remainder. And each boat must be full. IT'S IMPOSSIBLE TO HAVE PERSONS LEFT AT THE END OF THE PROGRAM!!! Who should they be reported to? The missing person's bureau? The only way I figure there can be persons left at the end is if the missionaries succeed in converting some of the cannibals to missionaries while waiting for a boat! Gads, with idiotic assignments like this that make no sense, no wonder I couldn't deal with programming classes. Marc MyXaml Advanced Unit Testing

                        T Offline
                        T Offline
                        toni kukuoc
                        wrote on last edited by
                        #11

                        You wrote: Now, I ask you, does arriving missionaries mean arriving at the departure boat or arriving at the other side of the river? I'm sooo confused!!! arriving at the departure boat You wrote: Is this an empty boat, ready to take on missionaries and cannibals, or is this a boat full of said people? yes this is empty boat and ready to take on missionaries and cannibals. You wrote: And exactly how many boats are on this river??? only one boat and/or two boat it is ur decision. You wrote: Since there's no upper limit on the number of cannibals and missionaries The number of cannibals must be greater than one, and the number of missionaries must be greater than two, finally the total number of persons should be multiples of three.ex:3 6 9 12 30 60 90 120 150 .....may be finally 210.ur choice You wrote: Certainly the instructions give NO CLUE as to how boats depart. Only arrive. So, in the end, the missionaries and cannibals should just be able to walk across the river, going from boat to boat. But to figure this out, we need to know more information about the river, it's width, the current, the size of each boat, etc. These are not input parameters! these ar not important.across the river 3 to 3 is important thing.others are not important. You wrote: How dumb is that! The parameters are clear: (M+A)/3 must not have a remainder. And each boat must be full. IT'S IMPOSSIBLE TO HAVE PERSONS LEFT AT THE END OF THE PROGRAM!!! at the end of the program you can print all missionaries and cannibals across the river. You wrote: Who should they be reported to? The missing person's bureau? The only way I figure there can be persons left at the end is if the missionaries succeed in converting some of the cannibals to missionaries while waiting for a boat! this is not important again. if you can do this homework with C, i am thanked you Thanks a lot:confused::confused: codingggggggggggggggggggg

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups