![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| semaphores using up and down | ddx08 | High Level Programming | 7 | 04-03-2007 11:38 PM |
| semaphores | kekanap | Shell Programming and Scripting | 1 | 03-27-2007 06:56 AM |
| semaphores | qntmteleporter | High Level Programming | 2 | 01-28-2006 08:10 PM |
| Semaphores with key of 0 | doeboy | UNIX for Advanced & Expert Users | 0 | 10-28-2004 04:41 PM |
| Semaphores | joseph_shibu | High Level Programming | 1 | 11-01-2001 01:01 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
How many semaphores?
Hello, first of all I apologize if this thread is not in the correct section of this forum, but this one just seemed the most appropriate.
The question I have does not concern Unix specifically, it applies to virtually any OS, however it is in Unix where I learned about this problem. So, the question is: What is the least number of semaphores needed to guarantee that n processes will run in a specified order ("chain of processes"), like this: P1 -> P2 -> P3 -> ...... -> Pn ? It means that P2 will not be allowed into critical section before P1 has exited it, P3 will not go before P2, and so on. I would really appreciate if you could comment on this, since I am trying to get the correct answer for quite some time and nobody I asked could provide the answer. Thank you. |
|
||||
|
No, I'm afraid not. A process can wait on more than one semaphore, so we don't need that many of them. I am told it is even less than log(n) with base 2 (!), although I cannot prove it.
|
|
||||
|
Quote:
Code:
Process1()
{
down(s1);down(s2); // waits on 2 semaphores
DoWork(); // performs job
up(s2);up(s3); // signals some semaphores
}
so I suppose we are to determine how can those semaphores be arranged in a way such that the least number of them is used. |
|
||||
|
1. Are the semaphores binary? Or can it start off at a value of n and will let you until it gets down to zero? 2. Can the process do Code:
up(s1); down(s2); up(s3) down(s4) doWork(); up(s4); down(s3); up(s2); down(s5); ? Last edited by porter; 11-07-2007 at 10:25 PM.. |
|
|||||
|
Quote:
Here at UNIX.COM we are interested in solving real-world problems, not doing homework for students. Thank you. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|