On Friday, 20 May 2016 at 02:04:56 UTC, captaindet wrote:
i am most curious about your solution.

why does printAll() has a synchronized block? in case you would call it before thread_joinAll() i.e. before all threads are terminated?

then again, why is there a synchronized block necessary in printAll() at all? it is only reading out data, not writing.

If a local copy/slice/range is made for foreach (which I think it is) then synchronized isn't needed. If reallocation worked differently then it could be quite annoying when the memory is reallocated and you were using it; But since it isn't, I just threw it in for completion sake.

(i am still learning the subtleties of multithreading.)

I tried to learn using C/C++ mutexes and semaphores and got hopelessly lost; Never tried to really get into it. Found a whole new meaning to the process while just recently re-reading the D2 book.

 Regardless, let's learn this stuff together :)

Still if you have any more complex commands then what you're doing here, you might wrap it into a class; It appears synchronized can work on classes (even Object) and not require a separate mutex for it to compile, so... I'm not sure what that means, or if it's even safe.

Reply via email to