parallelgzip icon indicating copy to clipboard operation
parallelgzip copied to clipboard

Do you want to use put instead of add?

Open rdifalco opened this issue 7 years ago • 4 comments

This was a great find, nice work.

Anyway, I wanted to point this out, not sure if you care. Pretty sure you want to block here.

https://github.com/shevek/parallelgzip/blob/master/src/main/java/org/anarres/parallelgzip/ParallelGZIPOutputStream.java#L233

rdifalco avatar Sep 18 '17 23:09 rdifalco

@rdifalco This is master thread only and emitQueue is an ArrayBlockingQueue. Can you clarify a bit?

simlu avatar Sep 30 '17 23:09 simlu

@simlu maybe I didn't read closely enough, but I figured since you are using an ArrayBlockingQueue that you'd want to block if the queue became full. Is it unbounded? I would have expected it to use put instead of add.

rdifalco avatar Oct 11 '17 20:10 rdifalco

Ah, now I see. I was pretty sure we deal with that in logic, but I don't see it right now.

Anyways, still a valuable change. Waiting rather than crashing is definitely preferred.

This seems legit and should be changed @shevek. I'll create a pr here shortly.

simlu avatar Oct 12 '17 01:10 simlu

The immediately preceding call to emitUntil() should ensure that an add() won't crash. It only returns when there's at least one space in the queue. Also, the testing has been sufficiently exhaustive on high-core-count machines that I'd be surprised if it had never shown up.

That said, this is still a good change, as it makes the software more robust, and still results in exactly one raising of the lock in ABQ, so I'll definitely take it. Good find, thank you.

shevek avatar Oct 12 '17 19:10 shevek