Time bounded code section, without threads

164 views
Skip to first unread message

Sumit Srivastava

unread,
Feb 25, 2016, 5:57:58 AM2/25/16
to mechanical-sympathy
Hi,

I have a code section which needs to be time bounded. Multi-threading is a way but might turn out to be costly in terms of context switch.

Responsiveness: Shall be flexible with no more than 5% time limit.
Missed time line: Return with partial result

Example: Real time bidding, if my code is not able to compute the bid in a specific time limit, it shall be skipped.

Let me know if more details are required.

Thanks,
Sumit

ymo

unread,
Feb 25, 2016, 2:06:54 PM2/25/16
to mechanical-sympathy
Assuming you have multiple computing threads and one collector thread. All you need is :
1) a collector thread that wakes up every 1000 ms from a sleep (to be simplistic) for example. 
2) The collector thread picks up items "produced" by computing threads while it was sleeping
3) computing threads do their *best effort* to compute and publish
4) if compute threads take too long to produce the collector thread will have nothing to do and can go back to sleep
5) the sleep time makes the whole thing time bounded and not costly from a multi threading point of view

If you try to do it all within the same thread you will introduce a lot of unnecessary complexity as well as calling System.mili multiple times to stay in time !
Reply all
Reply to author
Forward
0 new messages