| | |
Help for semaphores programming project ..
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2004
Posts: 31
Reputation:
Solved Threads: 0
man, this might be hard for me to get across the question i have ....
i have this project that requires using semaphores to do a project. (i have it attached).
i am just looking for help on how to start it, or whatever.
im just trying to understand where to begin.
ive understand how to use semaphores in dealing with "Producer-Consumer" problem, where one process (producer) will write to a buffer, and the other process (consumer) will read from the buffer.
but here, i have 23 seperate processes that i will need to synchronize ....
the problem:
there is a drawbridge ... we are to control the drawbridge to all south/north bound cars to go across, and let ships go under .....
so 10 threads represent 10 North Cars ... 12 processes represent 12 South Cars .... and 1 Thread represents all the ships....
i know ill need a semaphore for the bridge .....
but i dont understand how i will queue all the processes ... assignment says to not use any queue whatsoever (as the semaphores will create a queue itself) ....
wait, i think i just answered the question .....
when the threads get created, it should check to see if the bridge is free (if the bridge is "locked"), if not, the thread should go to sleep (which in turn, creates the queue for me) ... then after each thread/"car" goes through the bridge (the critical section), it will signal a new thread that is waiting (in the semaphore queue)
????
so, when i use semaphores for the drawbridge, should i use a binary semaphore (check if bridge is free or not), or a general semaphore (because i can only let 5 "cars"/threads go through the drawbridge at a time....
im thinking that i need just a binary sem, as only one car can go through at a time, thus, only 1 resource, so only need to check if its free or not ....
i will prob need more sem's ?
1 for bridge
1 for ships
1 for N Bound cars
1 for S Bound cars
(1 for the N and S bound cars. since only 5 cars can go through at a time, i need to block out the other cars. ex. its N bound cars turn. only 5 cars can go through. during that time, sem will block all S bound cars from being woken, or checked if its their turn to go through the bridge... after 5 N cars go through, then its S bound cars turn. as 5 S bound cars go through, N cars are blocked with sem from being checked, or woken ... all this of course, if there are no ships at the bridge, which means Ships get top priority).
??
any help on getting me started would be great. i think i know what to do, btu then, i think i dont.
i have this project that requires using semaphores to do a project. (i have it attached).
i am just looking for help on how to start it, or whatever.
im just trying to understand where to begin.
ive understand how to use semaphores in dealing with "Producer-Consumer" problem, where one process (producer) will write to a buffer, and the other process (consumer) will read from the buffer.
but here, i have 23 seperate processes that i will need to synchronize ....
the problem:
there is a drawbridge ... we are to control the drawbridge to all south/north bound cars to go across, and let ships go under .....
so 10 threads represent 10 North Cars ... 12 processes represent 12 South Cars .... and 1 Thread represents all the ships....
i know ill need a semaphore for the bridge .....
but i dont understand how i will queue all the processes ... assignment says to not use any queue whatsoever (as the semaphores will create a queue itself) ....
wait, i think i just answered the question .....
when the threads get created, it should check to see if the bridge is free (if the bridge is "locked"), if not, the thread should go to sleep (which in turn, creates the queue for me) ... then after each thread/"car" goes through the bridge (the critical section), it will signal a new thread that is waiting (in the semaphore queue)
????
so, when i use semaphores for the drawbridge, should i use a binary semaphore (check if bridge is free or not), or a general semaphore (because i can only let 5 "cars"/threads go through the drawbridge at a time....
im thinking that i need just a binary sem, as only one car can go through at a time, thus, only 1 resource, so only need to check if its free or not ....
i will prob need more sem's ?
1 for bridge
1 for ships
1 for N Bound cars
1 for S Bound cars
(1 for the N and S bound cars. since only 5 cars can go through at a time, i need to block out the other cars. ex. its N bound cars turn. only 5 cars can go through. during that time, sem will block all S bound cars from being woken, or checked if its their turn to go through the bridge... after 5 N cars go through, then its S bound cars turn. as 5 S bound cars go through, N cars are blocked with sem from being checked, or woken ... all this of course, if there are no ships at the bridge, which means Ships get top priority).
??
any help on getting me started would be great. i think i know what to do, btu then, i think i dont.
![]() |
Similar Threads
- Final Year Project help!!! (Computer Science)
- New Programming Project (IT Professionals' Lounge)
- Novice at PHP programming + Final year project (PHP)
- Shell Programming Project (Shell Scripting)
- First complete project (Geeks' Lounge)
- Require feedback on programming idea. (Computer Science)
- Programming Project (VB.NET)
Other Threads in the C Forum
- Previous Thread: new member here :)
- Next Thread: MP3 Player
| Thread Tools | Search this Thread |
Tag cloud for C
#include * append array arrays asterisks binarysearch calculate changingto char character cm command copyimagefile cprogramme creafecopyofanytypeoffileinc database directory dynamic execv feet fgets file fork forloop framework function functions givemetehcodez grade graphics gtkwinlinux hacking histogram homework include incrementoperators input intmain() iso kernel keyboard km lazy license linked linkedlist linux list lists locate logical_drives looping loopinsideloop. lowest matrix microsoft motherboard mqqueue number oddnumber odf opensource overwrite owf pdf performance pointer posix problem probleminc process program programming radix recursion recv recvblocked research reversing scanf scripting segmentationfault sequential socket socketprograming spoonfeeding standard string student systemcall testing threads turboc unix user variable wab whythiscodecausesegmentationfault windowsapi





