Skip to content

Commit

Permalink
Fix ld-decode deadlock on exit.
Browse files Browse the repository at this point in the history
On machines with small numbers of CPUs, ld-decode would sometimes
deadlock on exit, with two threads in different processes blocked
reading from pipes.

This turned out to be a race in the DemodCache destructor. It was doing:

for i in self.threads:
    if i.is_alive():
        self.q_in.put(None)

with the workers exiting when they received a None message. However,
suppose you've got two workers, and the following happens:

- DemodCache checks if A is alive - it is
- DemodCache sends None
- B receives None and exits
- DemodCache checks if B is alive - it isn't

A is now stuck waiting for a message that'll never arrive. I've fixed
this by removing the is_alive checks -- so it may now send more None
messages than necessary, but that's harmless.
  • Loading branch information
atsampson committed Dec 31, 2019
1 parent 5e9330b commit 47c4ade
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions lddecode/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -752,12 +752,10 @@ def __init__(self, rf, infile, loader, cachesize = 128, num_worker_threads=6, MT
def end(self):
# stop workers
for i in self.threads:
if i.is_alive():
self.q_in.put(None)
self.q_in.put(None)

for t in self.threads:
if t.is_alive():
t.join()
t.join()

self.q_out.put(None)

Expand Down

0 comments on commit 47c4ade

Please sign in to comment.