jaeSun 0 Light Poster

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.