[Openmcl-devel] Using suspend and resume (out of necessity)
Florian.Dietz2 at gmx.de
Fri Jul 5 05:17:33 CDT 2013
I am writing a multithreaded program that uses genetic programming
techniques to construct new functions from existing building blocks. The
purpose of this is to try to find heuristics to automatically generate
code to solve simple problems. Due to the nature of this task, I do not
have complete control over the code that some experimenting processes
are going to run. It is even possible that they may start going into an
infinite loop and there is nothing I can do to prevent that without
making the technique less powerful (as per the halting-problem).
I want to be able to pause these experimenting processes from the
outside (for prioritizing), but because I can't control what functions
they are going to run I need to use process-suspend for this. I also use
process-kill to stop them if I think they have hung up.
Unfortunately, there is a bug, but I think I know why:
Some of the building blocks of the constructed processes are critical
sections that should not be interrupted. To prevent this, I put locks
around them and make sure that before process-suspend or process-kill is
called, all locks are acquired first. The problem with this is that, as
I just realized, the functions process-suspend and process-kill may not
wait until they have taken effect before returning. Is this correct?
Because if it is, it is possible for my program to get into a deadlock
in the following way:
The manager process acquires all locks, calls process-suspend and
releases all locks again, but before the suspension actually takes
effect. The target process now enters a critical section, acquiring a
lock, but before it can leave the critical section again, the previously
called suspension takes effect. I now have a suspended process holding a
lock (is this actually possible or are locks automatically released on
suspension?). The next time the manager process wants to suspend or
resume a process, it will get stuck trying to acquire the lock that is
being held by the suspended process.
A similar problem also applies to process-kill, because a process should
not enter a critical section and then die so it never finishes all parts
of the critical section.
Do you know if my suspicions where the bug is coming from are correct?
If so, how can I do this instead?
More information about the Openmcl-devel