in reply to Re^3: Avoid Locking Entire Hashes
in thread Avoid Locking Entire Hashes
This is my safe set exerciser, which does crashes giving out the following error.
Thread <X> terminated abnormally: panic: MUTEX_LOCK (22) shared.xs:199 at ./thread_test.pl line 25.
I checked this multiple times but did not find anything wrong with it. May be a problem with the safe_set as I indicated in my post or may be not?
#! perl -slw use strict; use threads; use threads::shared; our %h : shared; # Setting up just a single row to increase chances # a race condition our $k = 'AAA'; our $val : shared = 0; our $THREADS = 50; our $iter = 50; $h{$k} = \$val; # Safe_set similar to BrowserUk sub safe_set { my $v :shared; # Critical Section { lock ${$h{$k}}; $v = ${$h{$k}} + 1; $h{$k} = \$v; } } # Keep locking to increment $$h{$k} sub test_safe_set { for (my $i = 0; $i < $iter; ++$i) { safe_set(); } } my @pool = map{ threads->create(\&test_safe_set) } 1 .. $THREADS; $_->join for @pool; warn ${$h{$k}}, "failed\n" if ${$h{$k}} != $THREADS * $iter;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Avoid Locking Entire Hashes
by BrowserUk (Patriarch) on Jun 15, 2011 at 18:27 UTC | |
by jagan_1234 (Sexton) on Jun 15, 2011 at 20:35 UTC | |
by BrowserUk (Patriarch) on Jun 15, 2011 at 21:45 UTC | |
by jagan_1234 (Sexton) on Jun 15, 2011 at 22:04 UTC | |
by BrowserUk (Patriarch) on Jun 15, 2011 at 22:25 UTC | |
|
Re^5: Avoid Locking Entire Hashes
by ikegami (Patriarch) on Jun 15, 2011 at 18:29 UTC |