sir there are two questions and i anxiously need there answers , please help me .... i am really very much thankful for that
==>> it is necessary to synchronize two or more processes so that
_every_ process completes the first phase of its program before _any_
process starts the second phase of its program. This is called barrier
synchronization. For two processes, we might write:
semaphores: init[process1] = 0; init[process2] = 0
process P1 = process P2 =
"phase I" "phase I"
V (process2) V (process1)
P (process1) P (process2)
"phase II" "phase II"
Using precisely this pattern with many, many processes would require a
large number of semaphores. One suggestion is to use a tree-like solution.
Suppose we have four (first-class) processes P1 through P4. Process Pj has
semaphores done[j] and go[j]. There are three intermediate processes T12,T34, and T1234. T12 has semaphores done[12] and go[12], etc. Here, T12waits for P1 and P2 to complete phase I and then alerts T1234. When T1234 learns (indirectly) that all of the Pj have completed phase I, he signals T12 and T34 to inform P1 through P4 that they may proceed with phase II.
? Write the code for process Pj and for intermediate process T12.
=================================
please reply me immediately
questions
- carbonBased
- Member
- Posts: 382
- Joined: Sat Nov 20, 2004 12:00 am
- Location: Wellesley, Ontario, Canada
- Contact:
Re: questions
I don't see why this can't be done with one semaphore that has a size of 'n' equal to the number of threads. A master task loops and 'downs' the semaphore 'n' times.mohsin wrote:it is necessary to synchronize two or more processes so that
_every_ process completes the first phase of its program before _any_
process starts the second phase of its program. This is called barrier
synchronization.
Each thread then 'ups' the semaphore at the end (or sync point) and waits for an event from the master task.
The master task is blocked until all threads up the semaphore, and so cannot send that event until the 'barrier' has been reached.
There are several other different ways to handle this case, of course. I don't see the need for 2*n semaphores.
--Jeff