Adobe Interview Question
Software Engineer / Developerswhat if the situation is
at t = 0, setOStimer(10,fn,arg)
at t = 4, setOStimer(2,fn1,arg1).
here fn1 should be called before fn.
Possible solution is :
Make a list of all functions with extra field SRT(shortest remaining time)
after each second:
1.)Add new function in list (if any) with SRT=time provided with fn call;
2.)SRT-=1;
3.)If SRT==0 call function with setOStimer(0,fn,arg);
1st we've to ask interviewer if setOStimer is non-blocking call or blocking call.
If its blocking call then we just have to wait till first timer expires.
But i guess it should be a non-blocking call.
Now in ur own API, call the given API with timer=t1(=5).
After delta(=4sec in this case) another timer need to be started.
Check if (t1-delta > 0) then wait in some(u can maintain a while loop with this condition), once this condition fails(u can come to know about this thru some SW interrupt) then once again call the given API with timer=t2(=10 + t1-delta(=5))
Use setOStimer () as periodic timer (of say 1 sec. We can achieve this by calling setOStimer in the callback fucntion).
Now, we can add new entries added via setTimer() into a wheel and use setOSTimer() as ticks.
I can think of few of approaches but whatever I just mentioned seems to be the most optimal.
May be we should should use the synchronized mechanism to make the other timer wait till the first timer is done.
- Anonymous March 12, 2011