May 20, 2016 Re: How to share an appender!string? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Era Scarecrow | On 2016-05-20 07:49, Era Scarecrow wrote:
> Experimented and quickly got what looks like good clean results. Took
> your code, ripped out what I didn't want and added in what I did. Simple!
>
> https://dpaste.dzfl.pl/6952fdf463b66
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.
(i am still learning the subtleties of multithreading.)
/det
|
May 20, 2016 Re: How to share an appender!string? | ||||
---|---|---|---|---|
| ||||
Posted in reply to captaindet | 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. |
Copyright © 1999-2021 by the D Language Foundation