in reply to Re^6: does threads (still) memleak?
in thread does threads (still) memleak?
One thing. In my example, for the sake of simplicity, I use printf from multiple threads, without any form of locking. I can get away with this, as long as the output is going to the screen, because on my system the OS serialises the output.
If your system doesn't do this, or (for example) if you want to be able to re-direct the output file, then you should (I should) be using a semaphore. A simple way to do that is to wrap print/printf something like:
my $stdOutSem :shared; sub tprint { lock $stdoutSem; print ref( $_[0] ) eq 'GLOB' ? shift() : () "[@{[ threads->tid ]}] +:", @_; } sub tprintf { lock $stdoutSem; printf ref( $_[0] ) eq 'GLOB' ? shift() : () "[%s]" . $_[0], $_[ 1 + .. $#_ ]; }
Refactor and season to taste.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^8: does threads (still) memleak?
by faxm0dem (Novice) on Nov 27, 2008 at 14:45 UTC | |
by BrowserUk (Patriarch) on Nov 27, 2008 at 15:13 UTC | |
by faxm0dem (Novice) on Nov 27, 2008 at 15:31 UTC | |
by BrowserUk (Patriarch) on Nov 27, 2008 at 16:19 UTC | |
by faxm0dem (Novice) on Nov 27, 2008 at 16:52 UTC | |
| |
by faxm0dem (Novice) on Nov 28, 2008 at 13:02 UTC | |
|