Consider a time scale. At random points in time, there will be register callback functions invoked. The callback functions are waiting on an event that will be fired at some point in time. By the time the caller registers the callback, if the event had happened, the caller should execute the function, otherwise, the callback needs to be registered and executed once the event has fired. After the event has fired, any callback dependent on the event can be executed without having to register. 1. Solve for single threaded application case 2. Solve for multi-threaded application case 2a. How to ensure that the register callback functions do not wait excessively to queue in the callback?
Anonymous
The interviewer was looking for basic knowledge on threading. I wasn't aware that I was allowed to use MT-safe data structures. Therefore, attempted to make the callback queue thread-safe while guaranteeing low wait times, and that took sometime. He was looking for the understanding of memory barrier, atomicity, race conditions and parallel execution fundamentals.
Check out your Company Bowl for anonymous work chats.