Rob Arthan wrote:
Happy New Year to the Poly/ML User Community!
I am trying to find a fix to a problem where we want to apply a function that sometimes takes far too long to execute. So I want to abort execution of the function after a specified time limit. I have a solution that seems to work by forking a worker thread to execute the function and store the result in a ref while the control thread goes into a loop that waits for 100ms and then either (1) returns the result from the ref if the worker thread is no longer active, (2) repeats if the thread is still active and we haven?t reaced the time limit or otherwise (3) kills the worker thread and returns a dummy value.
I am implementing this using Thread.ConditionVar.waitUntil and have two questions about that:
- What does the bool returned by Thread.ConditionVar.waitUntil mean? That doesn?t seem
to be documented.
While not a Poly/ML -specific answer, this would be the indication of whether, when execution continues after the wait, it is because the wait condition was satisfied OR the timeout expired (not 100% which value means which, but you should be able to determine that rather easily).
- In addition to the timeout, Thread.ConditionVar.waitUntil has a condition variable and a mutex
as arguments. I am just creating these using Thread.ConditionVar.conditionVar and Thread.Mutex.mutex because I need some values to pass to Thread.ConditionVar.waitUntil. I am not doing any signalling or locking or unlocking. Is that going to cause any problems? (The condition variable and the mutex are local to the control thread function, so the worker thread function has no access to them.)
The associated mutex is used to "protect" the condition variable itself, so that while it is examining the condition, things can't change out from under it - that's all.
Good luck, and feel free to request further clarification.
Robert Roessler