Hi...
I have some doubts in your reply. Whenever the data comes, How the process B, knows the data is available in the stream..
I think the process done by Process B are
1. Check for the data available in the stream.
2. If the data is available, then check for the free space available in the pool.
Then get the data from the stream, copy the data to the pool of free space
3. then, at last, give an intimation to the process A.
4. if the data in the pool, is taken by process A, then Log the data in a file.
5. wait for the data
Am i correct?
Now i bit clear about what you want to do....
/* semaphore is used to give a signal to another process here */
Semaphore var = 0; /* var semaphore is locked, which means some
has to unlock it, then only any one can lock it.*/
Semaphore var1 = 1; /* any one can do semaphore lock *.*/
Queue q /* it used to pass information b/w two process */
Process B() {
while(1){
Lock semaphore(var); /* here is Process B becuse 'var=0' this var can be 1, when
process A executes 'Unlock semaphore(var);'
Means that process a after completes it work, it send a signal
to process B.
i.e waiting for a signal from process 'A'*/
read from a Q(q); /* Once the process 'A' unlocks Process 'B' reads from the Q
Note Now Process B is process processing but Process is locked
by semaphore var1 . until some one else unlock the semaphore
Process 'A' can not be continue*/
Unlock semaphore(var1);/* Okay Process 'B' took informtaion from the Q, so it has
Enoguh informtion to proceed, Now it can unlock the send a
signal to Process 'A' to continue by unlocking the semaphore
'var1' Unlock semaphore(var1)
Send a signal to process 'A'*/
Do your work. /* do your work*/
} /* end while */
}
Process A(){
while (1){
Lock semaphore(var1) /* var1=1 so process a can get lock...., it will not wait for anything
first time..., Note it is not unlock this semaphore..., which
second third etc it can not lock again, some one has to unlock
it then only it can lock 2nd and 3rd time.
Who is unlocking it, it done by Process 'B' i.e just receving
signal to Process 'B' to continue
*/
Do your work; /* Do your work */
write into a Q(q); /* write into a Q */
Unlock semaphore(var); /* var was 0, Now unlock this semaphore leads var=1, so process B
can continue becuse Proceess 'B' 'Lock semaphore(var);' process
A to unlock. it is signal sending a signal to process B
to continue */
}
}
Feel free to discuss more on this.....
Regards,
Arul