Daniel Martí: >> I haven't done much fancy concurrency, but one idea that came to mind is >> this: >> >> * have a counter for instances of your probe thread >> * have `synchronized` increment/decrement methods >> * as each thread starts, it increments the counter >> * as each thread finishes, it decrements the counter >> * include a timeout in the thread so they return in a reasonable amount of >> time >> * have a while loop that quits when the counter is back to 0 >> * now you have your result >> >> .hc > > This had occured to me, and is pretty much how WaitGroups work in Go. > Two issues though: > > * Doesn't a while() take 100% of the CPU on a thread? The good thing of > WaitGroups is that they use channels, which block kinda like a read() > and so consume no CPU.
Yes, if you let it. Just add a Thread.sleep(1000) or something. Or you could just add the check in the decrement method to run a callback once 0 is hit. .hc > * Adding that manual waitgroup would bring up the total line count to > over 100 lines. It really sounds like it could be done in a cleaner, > easier and perhaps even faster way. -- PGP fingerprint: 5E61 C878 0F86 295C E17D 8677 9F0F E587 374B BE81 https://pgp.mit.edu/pks/lookup?op=vindex&search=0x9F0FE587374BBE81 _______________________________________________ List info: https://lists.mayfirst.org/mailman/listinfo/guardian-dev To unsubscribe, email: [email protected]
