diff options
Diffstat (limited to 'ext')
-rw-r--r-- | ext/B/B/CC.pm | 4 | ||||
-rw-r--r-- | ext/B/byteperl.c | 8 | ||||
-rw-r--r-- | ext/POSIX/hints/bsdos.pl | 3 | ||||
-rw-r--r-- | ext/POSIX/hints/freebsd.pl | 3 | ||||
-rw-r--r-- | ext/POSIX/hints/netbsd.pl | 3 | ||||
-rw-r--r-- | ext/POSIX/hints/openbsd.pl | 3 | ||||
-rw-r--r-- | ext/Thread/Thread.pm | 127 |
7 files changed, 148 insertions, 3 deletions
diff --git a/ext/B/B/CC.pm b/ext/B/B/CC.pm index fc7cf6dad2..4c877d9c5b 100644 --- a/ext/B/B/CC.pm +++ b/ext/B/B/CC.pm @@ -788,7 +788,7 @@ BEGIN { my $divide_op = infix_op("/"); my $modulo_op = infix_op("%"); my $lshift_op = infix_op("<<"); - my $rshift_op = infix_op("<<"); + my $rshift_op = infix_op(">>"); my $ncmp_op = sub { "($_[0] > $_[1] ? 1 : ($_[0] < $_[1]) ? -1 : 0)" }; my $scmp_op = prefix_op("sv_cmp"); my $seq_op = prefix_op("sv_eq"); @@ -1438,7 +1438,7 @@ sub compile { last OPTION; } elsif ($opt eq "o") { $arg ||= shift @options; - open(STDOUT, ">$arg") or return "$arg: $!\n"; + open(STDOUT, ">$arg") or return "open '>$arg': $!\n"; } elsif ($opt eq "n") { $arg ||= shift @options; $module_name = $arg; diff --git a/ext/B/byteperl.c b/ext/B/byteperl.c index a42edfb8d5..323d63a809 100644 --- a/ext/B/byteperl.c +++ b/ext/B/byteperl.c @@ -37,7 +37,11 @@ main(int argc, char **argv, char **env) if (!do_undump) { my_perl = perl_alloc(); if (!my_perl) +#ifdef VMS + exit(vaxc$errno); +#else exit(1); +#endif perl_construct( my_perl ); } @@ -56,7 +60,11 @@ main(int argc, char **argv, char **env) #endif if (!fp) { perror(argv[1]); +#ifdef VMS + exit(vaxc$errno); +#else exit(1); +#endif } argv++; argc--; diff --git a/ext/POSIX/hints/bsdos.pl b/ext/POSIX/hints/bsdos.pl new file mode 100644 index 0000000000..62732ac7b9 --- /dev/null +++ b/ext/POSIX/hints/bsdos.pl @@ -0,0 +1,3 @@ +# BSD platforms have extra fields in struct tm that need to be initialized. +# XXX A Configure test is needed. +$self->{CCFLAGS} = $Config{ccflags} . ' -DSTRUCT_TM_HASZONE' ; diff --git a/ext/POSIX/hints/freebsd.pl b/ext/POSIX/hints/freebsd.pl new file mode 100644 index 0000000000..62732ac7b9 --- /dev/null +++ b/ext/POSIX/hints/freebsd.pl @@ -0,0 +1,3 @@ +# BSD platforms have extra fields in struct tm that need to be initialized. +# XXX A Configure test is needed. +$self->{CCFLAGS} = $Config{ccflags} . ' -DSTRUCT_TM_HASZONE' ; diff --git a/ext/POSIX/hints/netbsd.pl b/ext/POSIX/hints/netbsd.pl new file mode 100644 index 0000000000..62732ac7b9 --- /dev/null +++ b/ext/POSIX/hints/netbsd.pl @@ -0,0 +1,3 @@ +# BSD platforms have extra fields in struct tm that need to be initialized. +# XXX A Configure test is needed. +$self->{CCFLAGS} = $Config{ccflags} . ' -DSTRUCT_TM_HASZONE' ; diff --git a/ext/POSIX/hints/openbsd.pl b/ext/POSIX/hints/openbsd.pl new file mode 100644 index 0000000000..62732ac7b9 --- /dev/null +++ b/ext/POSIX/hints/openbsd.pl @@ -0,0 +1,3 @@ +# BSD platforms have extra fields in struct tm that need to be initialized. +# XXX A Configure test is needed. +$self->{CCFLAGS} = $Config{ccflags} . ' -DSTRUCT_TM_HASZONE' ; diff --git a/ext/Thread/Thread.pm b/ext/Thread/Thread.pm index cf7069c45d..c8bca0db71 100644 --- a/ext/Thread/Thread.pm +++ b/ext/Thread/Thread.pm @@ -32,7 +32,132 @@ Thread - multithreading =head1 DESCRIPTION -The C<Threads> module provides multithreading. +The C<Thread> module provides multithreading support for perl. + +=head1 FUNCTIONS + +=over 8 + +=item new \&start_sub + +=item new \&start_sub, LIST + +C<new> starts a new thread of execution in the referenced subroutine. The +optional list is passed as parameters to the subroutine. Execution +continues in both the subroutine and the code after the C<new> call. + +C<new Thread> returns a thread object representing the newly created +thread. + +=item lock VARIABLE + +C<lock> places a lock on a variable until the lock goes out of scope. If +the variable is locked by another thread, the C<lock> call will block until +it's available. C<lock> is recursive, so multiple calls to C<lock> are +safe--the variable will remain locked until the outermost lock on the +variable goes out of scope. + +Locks on variables only affect C<lock> calls--they do I<not> affect normal +access to a variable. (Locks on subs are different, and covered in a bit) +If you really, I<really> want locks to block access, then go ahead and tie +them to something and manage this yourself. This is done on purpose. While +managing access to variables is a good thing, perl doesn't force you out of +its living room... + +If a container object, such as a hash or array, is locked, all the elements +of that container are not locked. For example, if a thread does a C<lock +@a>, any other thread doing a C<lock($a[12])> won't block. + +You may also C<lock> a sub, using C<lock &sub>. Any calls to that sub from +another thread will block until the lock is released. This behaviour is not +equvalent to C<use attrs qw(locked)> in the sub. C<use attrs qw(locked)> +serializes access to a subroutine, but allows different threads +non-simultaneous access. C<lock &sub>, on the other hand, will not allow +I<any> other thread access for the duration of the lock. + +Finally, C<lock> will traverse up references exactly I<one> level. +C<lock(\$a)> is equivalent to C<lock($a)>, while C<lock(\\$a)> is not. + +=item async BLOCK; + +C<async> creates a thread to execute the block immediately following +it. This block is treated as an anonymous sub, and so must have a +semi-colon after the closing brace. Like C<new Thread>, C<async> returns a +thread object. + +=item Thread->self + +The C<Thread-E<gt>self> function returns a thread object that represents +the thread making the C<Thread-E<gt>self> call. + +=item Thread->list + +C<Thread-E<gt>list> returns a list of thread objects for all running and +finished but un-C<join>ed threads. + +=item cond_wait VARIABLE + +The C<cond_wait> function takes a B<locked> variable as a parameter, +unlocks the variable, and blocks until another thread does a C<cond_signal> +or C<cond_broadcast> for that same locked variable. The variable that +C<cond_wait> blocked on is relocked after the C<cond_wait> is satisfied. +If there are multiple threads C<cond_wait>ing on the same variable, all but +one will reblock waiting to reaquire the lock on the variable. (So if +you're only using C<cond_wait> for synchronization, give up the lock as +soon as possible) + +=item cond_signal VARIABLE + +The C<cond_signal> function takes a locked variable as a parameter and +unblocks one thread that's C<cond_wait>ing on that variable. If more than +one thread is blocked in a C<cond_wait> on that variable, only one (and +which one is indeterminate) will be unblocked. + +If there are no threads blocked in a C<cond_wait> on the variable, the +signal is discarded. + +=item cond_broadcast VARIABLE + +The C<cond_broadcast> function works similarly to C<cond_wait>. +C<cond_broadcast>, though, will unblock B<all> the threads that are blocked +in a C<cond_wait> on the locked variable, rather than only one. + +=back + +=head1 METHODS + +=over 8 + +=item join + +C<join> waits for a thread to end and returns any values the thread exited +with. C<join> will block until the thread has ended, though it won't block +if the thread has already terminated. + +If the thread being C<join>ed C<die>d, the error it died with will be +returned at this time. If you don't want the thread performing the C<join> +to die as well, you should either wrap the C<join> in an C<eval> or use the +C<eval> thread method instead of C<join>. + +=item eval + +The C<eval> method wraps an C<eval> around a C<join>, and so waits for a +thread to exit, passing along any values the thread might have returned. +Errors, of course, get placed into C<$@>. + +=item tid + +The C<tid> method returns the tid of a thread. The tid is a monotonically +increasing integer assigned when a thread is created. The main thread of a +program will have a tid of zero, while subsequent threads will have tids +assigned starting with one. + +=head1 LIMITATIONS + +The sequence number used to assign tids is a simple integer, and no +checking is done to make sure the tid isn't currently in use. If a program +creates more than 2^32 - 1 threads in a single run, threads may be assigned +duplicate tids. This limitation may be lifted in a future version of Perl. =head1 SEE ALSO |