l...@gnu.org (Ludovic Courtès) writes: > Mark H Weaver <m...@netris.org> skribis: > >> + ;; setting 'create-workers!' to a no-op is an optimization, but it is >> + ;; still possible for '%create-workers!' to be called more than once >> + ;; from different threads. Therefore, to avoid creating %workers more >> + ;; than once (and thus creating too many threads), we check to make >> + ;; sure %workers is empty within the critical section. > > Do you have a scenario where this happens?
I'd hoped that the comment above was clear, but let me try again. If two threads simultaneously call 'make-future' before the worker pool has been created, then both threads can call 'create-workers!' (before it has been rebound), and from there both can enter '%create-workers!'. At that point, unless one of the threads is killed, it is guaranteed that both will enter the critical section: first one, and then the other (after the first one has unlocked the mutex). Thus, two worker pools will be created (though the first worker pool will become inaccessible). Mark