Click to See Complete Forum and Search --> : Sequencing or queuing parallel process


sv_joshi_pune
August 13th, 2009, 08:54 AM
Scenario is as follows
There is one parent process say P1 and 4 child processes say A B C D

Process A starts at 3:00 pm
Process B starts at 3:15 pm
Process C starts at 3:30 pm
Process D starts at 3:45 pm

Process A take 1 hour for completion and process B,C,D takes 10 mins for completion
At a time only one process is allowed to execute since these process shared some common resources so at any point of time only one process is allowed to execute. but these are scheduled job so process B, C, and D must wait till process A get completes

so process B must wait till 4:00 PM for execution
and starts at 4:00 PM
process C must start at 4:10 PM after completion of process A and B
process D must start at 4:20 PM after completion of process A and B and C
so these sequencing also should maintained

B, C and D cannot start unless and until A is get completed and user dose not know
How much time A will take so B,C and D must wait for completion of A and after A completes then and then only B,C and D execute in a same order

so how to implement wait mechanism for this scenario?

Currently i have implemented a lock mechanism where first process A will create a lock file and process B,C and D will continuously poll this lock file and as soon as process A finishes it will release a lock on and whichever process acquires a lock first will get executed first but here sequencing is not maintained and process executes randomly

so what kernel objects like event, semaphore are needed to solve this scenario.

please help to solve this scenario of process waiting for execution in a queue.

-Thanks

Arjay
August 13th, 2009, 04:34 PM
You definitely shouldn't be polling because polling is a waste of resources.

Assuming you are on Windows, create 3 named events - hProcessACompletedEvent, hProcessBCompletedEvent, and hProcessCCompletedEvent.

Process A starts and when it finishes, sets the hProcessACompletedEvent.

Process B starts and opens a handle to hProcessACompletedEvent and then waits for this event before starting its processing. When B completes its processing, it sets the hProcessBCompletedEvent.

The setup for Process C & D are similar to B.