From: Artur Bergman Date: Sat, 27 Apr 2002 23:50:11 +0000 (+0000) Subject: Removed last traces of autodetach. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=678a9b6c63252a38ff5453e7acc1b7b4bf5b7197;p=p5sagit%2Fp5-mst-13.2.git Removed last traces of autodetach. Added list() methid. Changed documentation. p4raw-id: //depot/perl@16235 --- diff --git a/ext/threads/threads.pm b/ext/threads/threads.pm index c6f7875..a8a340f 100755 --- a/ext/threads/threads.pm +++ b/ext/threads/threads.pm @@ -52,7 +52,7 @@ our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); our @EXPORT = qw( ); -our $VERSION = '0.05'; +our $VERSION = '0.99'; sub equal { @@ -101,6 +101,8 @@ $thread->tid(); threads->yield(); +threads->list(); + =head1 DESCRIPTION Perl 5.6 introduced something called interpreter threads. Interpreter @@ -135,7 +137,7 @@ object. This will wait for the corresponding thread to join. When it finishes join will return the return values of the entry point function. If a -thread has been detached, join will return without wait. +thread has been detached, an error will be thrown.. =item $thread->detach @@ -148,14 +150,18 @@ This will return the object for the current thread. =item $thread->tid -This will return the id of the thread. threads->self->tid() is a -quick way to get current thread id. +This will return the id of the thread. threads->tid() is a quick way +to get current thread id if you don't have your thread handy. =item threads->yield(); This will tell the OS to let this thread yield CPU time to other threads. However this is highly depending on the underlying thread implmentation. +=item threads->list(); + +This will return a list of all non joined, non detached threads. + =back =head1 WARNINGS @@ -170,15 +176,38 @@ or somehow be certain that all the non-main threads have finished. =back -=head1 TODO +=head1 BUGS / TODO + +The current implmentation of threads has been an attempt to get +a correct threading system working that could be built on, +and optimized, in newer versions of perl. + +Current the overhead of creating a thread is rather large, +also the cost of returning values can be large. These are areas +were there most likely will be work done to optimize what data +that needs to be cloned. =over -=item Fix so the return value is returned when you join. +=item Parent-Child threads. + +On some platforms it might not be possible to destroy "parent" +threads while there are still existing child "threads". + +This will be possibly be fixed in later versions of perl. + +=item tid is I32 + +The tid is a 32 bit integer, it can potentially overflow. +This might be fixed in a later version of perl. -=item Add join_all. +=item Returning objects -=item Fix memory leaks! +When you return an object the entire stash that the object is blessed +as well. This will lead to a large memory usage. +The ideal situation would be to detect the original stash if it existed. + +=item PERL_OLD_SIGNALS are not threadsafe, will not be. =back @@ -203,16 +232,8 @@ Helping with debugging. please join perl-ithreads@perl.org for more information -=head1 BUGS - -=over - -=item creating a thread from within a thread is unsafe under win32 - -=item PERL_OLD_SIGNALS are not threadsafe, will not be. -=back =head1 SEE ALSO diff --git a/ext/threads/threads.xs b/ext/threads/threads.xs index 835cd63..ff2df9d 100755 --- a/ext/threads/threads.xs +++ b/ext/threads/threads.xs @@ -367,7 +367,6 @@ Perl_ithread_create(pTHX_ SV *obj, char* classname, SV* init_function, SV* param MUTEX_INIT(&thread->mutex); thread->tid = tid_counter++; thread->gimme = GIMME_V; - thread->state = (thread->gimme == G_VOID) ? 1 : 0; /* "Clone" our interpreter into the thread's interpreter * This gives thread access to "static data" and code. @@ -553,6 +552,23 @@ CODE: } void +ithread_list(char *classname) +PPCODE: +{ + ithread *curr_thread; + MUTEX_LOCK(&create_destruct_mutex); + curr_thread = threads; + while(curr_thread) { + PUSHs( ithread_to_SV(aTHX_ NULL, curr_thread, classname, TRUE)); + curr_thread = curr_thread->next; + if(curr_thread == threads) + break; + } + MUTEX_UNLOCK(&create_destruct_mutex); +} + + +void ithread_self(char *classname) CODE: {