Wednesday, 21 August 2013

synchronizing workers Algorithm

synchronizing workers Algorithm

I have a scenario, where i am monitoring a dozen of stocks.
Worker
worker (a method) takes a stock (assigned by manager), Monitors it for 5
consecutive negative Units. Each unit is say 0.5% of a stock price. Eg:
for a stock, costing 100$. Each unit is 50C.
If its price falls to 99.4$ => One unit down. (Intermediate fluctuations
in a unit are OK.)
If its price falls to 98.8$ => Two units down from 100$
If its price falls to 98.4$ => Three units down from 100$
IF a stock price goes down by 5 units, the worker reports to manager. End
method here. iF a stock price moves up by 2 units, report to manager and
end method here.
Manager
Assigns a worker for each of these dozen stocks. (Calling the same method.
Thread: Non Blocking) Wait till all of them terminate. check if all of the
stocks are moving up/down.
If all are moving up, Call "Handle_Rising Market" method
If all are moving down, Call "Handle_Crashing_Market" method
If some are moving up, and some moving down, Call worker again for each of
them, Manager must end only when all report either UP or DOWN. till then
the check must go on.
I am looking for the fastest algorithm. This is a traditional Worker
manager problem, with extra scenarios. The repeated check to ensure that
all of them are moving up/down is where i am stuck! Any advice is highly
appreciated.

No comments:

Post a Comment