diff options
author | Artur Bergman <sky@nanisky.com> | 2003-04-21 13:24:40 +0000 |
---|---|---|
committer | Artur Bergman <sky@nanisky.com> | 2003-04-21 13:24:40 +0000 |
commit | 9c98058e3a5614fae5d400e2119d67d3c97a64d1 (patch) | |
tree | d3328ac91a40787d4558076c6d58fb29c6899b06 /ext/threads | |
parent | 15b61c98f82f3010e6eaa852f9fa5251de9e6dd9 (diff) | |
download | perl-9c98058e3a5614fae5d400e2119d67d3c97a64d1.tar.gz |
Fixes bug #17043, resets PL_srand_called before the cloning.
Allows people to override the resetting by using srand() in CLONE.
p4raw-id: //depot/perl@19289
Diffstat (limited to 'ext/threads')
-rw-r--r-- | ext/threads/t/thread.t | 16 | ||||
-rwxr-xr-x | ext/threads/threads.xs | 6 |
2 files changed, 20 insertions, 2 deletions
diff --git a/ext/threads/t/thread.t b/ext/threads/t/thread.t index 9a2bb28b7e..d03975ab1e 100644 --- a/ext/threads/t/thread.t +++ b/ext/threads/t/thread.t @@ -12,7 +12,7 @@ BEGIN { use ExtUtils::testlib; use strict; -BEGIN { $| = 1; print "1..24\n" }; +BEGIN { $| = 1; print "1..25\n" }; use threads; use threads::shared; @@ -140,4 +140,18 @@ package main; ok($th); ok($th->join()); } +{ + # there is a little chance this test case will falsly fail + # since it tests rand + my %rand : shared; + rand(10); + threads->new( sub { $rand{int(rand(10000000000))}++ } ) foreach 1..25; + $_->join foreach threads->list; +# use Data::Dumper qw(Dumper); +# print Dumper(\%rand); + #$val = rand(); + ok((keys %rand == 25), "Check that rand works after a new thread"); +} + + diff --git a/ext/threads/threads.xs b/ext/threads/threads.xs index b50aa46329..a12c1a8782 100755 --- a/ext/threads/threads.xs +++ b/ext/threads/threads.xs @@ -399,7 +399,10 @@ Perl_ithread_create(pTHX_ SV *obj, char* classname, SV* init_function, SV* param PerlIO_flush((PerlIO*)NULL); PERL_THREAD_SETSPECIFIC(self_key,thread); - + SAVEBOOL(PL_srand_called); /* Save this so it becomes the correct + value */ + PL_srand_called = FALSE; /* Set it to false so we can detect + if it gets set during the clone */ #ifdef WIN32 thread->interp = perl_clone(aTHX, CLONEf_KEEP_PTR_TABLE | CLONEf_CLONE_HOST); @@ -413,6 +416,7 @@ Perl_ithread_create(pTHX_ SV *obj, char* classname, SV* init_function, SV* param */ { dTHXa(thread->interp); + /* Here we remove END blocks since they should only run in the thread they are created */ |