Fixed #2294 - Classes sometimes cannot be found
This patch should fix the race condition causing ticket 2294; it extends the loading logic so that:
- initial load attempts are processed (as before),
- recursive load attempts return immediately (as before),
- but subsequent concurrent load attempts from different threads wait on a semaphore (condition variable) and then retry (e.g. use the now-valid results of the first thread).
This is a slight modification of the solution I'd originally proposed, to prevent a deadlock
that could have arisen if three or more threads simultaneously attempted to load the same item.
Though it solves the bug as reported, it has room for improvement:
- Failures aren't cached, so repeated attempts will be made to import invalid items each time they are encountered
- It doesn't address any of the underlying referential ambiguity (module vs. filename)
- The threading logic should probably be refactored into a separate class (as a start I encapsulated it in an ad hoc singleton class, so at least it isn't cluttering up the load method)
Signed-off-by: Markus Roberts <Markus@reality.com>