From af36542000fc547506d8dc9b952c200b8499830d Mon Sep 17 00:00:00 2001 From: Gurusamy Sarathy Date: Thu, 9 Dec 1999 10:22:31 +0000 Subject: [PATCH] USE_ITHREADS tweaks and notes p4raw-id: //depot/perl@4675 --- op.c | 16 +++++++++++----- pod/perldelta.pod | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++----- sv.c | 18 ++++++++++++++++-- 3 files changed, 79 insertions(+), 12 deletions(-) diff --git a/op.c b/op.c index 4f8ab08..e69630a 100644 --- a/op.c +++ b/op.c @@ -23,10 +23,17 @@ /* #define PL_OP_SLAB_ALLOC */ /* XXXXXX testing */ -#define OP_REFCNT_LOCK NOOP -#define OP_REFCNT_UNLOCK NOOP -#define OpREFCNT_set(o,n) NOOP -#define OpREFCNT_dec(o) ((o)->op_targ--) +#ifdef USE_ITHREADS +# define OP_REFCNT_LOCK NOOP +# define OP_REFCNT_UNLOCK NOOP +# define OpREFCNT_set(o,n) ((o)->op_targ = (n)) +# define OpREFCNT_dec(o) (--(o)->op_targ) +#else +# define OP_REFCNT_LOCK NOOP +# define OP_REFCNT_UNLOCK NOOP +# define OpREFCNT_set(o,n) NOOP +# define OpREFCNT_dec(o) 0 +#endif #ifdef PL_OP_SLAB_ALLOC #define SLAB_SIZE 8192 @@ -660,7 +667,6 @@ Perl_op_free(pTHX_ OP *o) OP_REFCNT_UNLOCK; return; } - o->op_targ = 0; /* XXXXXX */ OP_REFCNT_UNLOCK; break; default: diff --git a/pod/perldelta.pod b/pod/perldelta.pod index 924996d..2ea14a2 100644 --- a/pod/perldelta.pod +++ b/pod/perldelta.pod @@ -141,7 +141,7 @@ work. The following previously allowed construct: print not (1,2,3)[0]; -needs to written with additional parentheses now: +needs to be written with additional parentheses now: print not((1,2,3)[0]); @@ -166,6 +166,10 @@ specified via MakeMaker: =item C +PERL_IMPLICIT_CONTEXT is automatically enabled whenever Perl is built +with one of -Dusethreads, -Dusemultiplicity, or both. It is not +intended to be enabled by users at this time. + This new build option provides a set of macros for all API functions such that an implicit interpreter/thread context argument is passed to every API function. As a result of this, something like C @@ -182,9 +186,6 @@ Note that the above issue is not relevant to the default build of Perl, whose interfaces continue to match those of prior versions (but subject to the other options described here). -PERL_IMPLICIT_CONTEXT is automatically enabled whenever Perl is built -with one of -Dusethreads, -Dusemultiplicity, or both. - See L for detailed information on the ramifications of building Perl using this option. @@ -320,6 +321,52 @@ Perl can optionally use UTF-8 as its internal representation for character strings. The C pragma enables this support in the current lexical scope. See L for more information. +=head2 Interpreter threads + +WARNING: This is an experimental feature in a pre-alpha state. Use +at your own risk. + +Perl 5.005_63 introduces the beginnings of support for running multiple +interpreters concurrently in different threads. In conjunction with +the perl_clone() API call, which can be used to selectively duplicate +the state of any given interpreter, it is possible to compile a +piece of code once in an interpreter, clone that interpreter +one or more times, and run all the resulting interpreters in distinct +threads. + +On Windows, this feature is used to emulate fork() at the interpreter +level. See L. + +This feature is still in evolution. It is eventually meant to be used +to selectively clone a subroutine and data reachable from that +subroutine in a separate interpreter and run the cloned subroutine +in a separate thread. Since there is no shared data between the +interpreters, little or no locking will be needed (unless parts of +the symbol table are explicitly shared). This is obviously intended +to be an easy-to-use replacement for the existing threads support. + +Support for cloning interpreters must currently be manually enabled +by defining the cpp macro USE_ITHREADS on non-Windows platforms. +(See win32/Makefile for how to enable it on Windows.) The resulting +perl executable will be functionally identical to one that was built +without USE_ITHREADS, but the perl_clone() API call will only be +available in the former. + +USE_ITHREADS enables Perl source code changes that provide a clear +separation between the op tree and the data it operates with. The +former is considered immutable, and can therefore be shared between +an interpreter and all of its clones, while the latter is considered +local to each interpreter, and is therefore copied for each clone. + +Note that building Perl with the -Dusemultiplicity Configure option +is adequate if you wish to run multiple B interpreters +concurrently in different threads. USE_ITHREADS only needs to be +enabled if you wish to obtain access to perl_clone() and cloned +interpreters. + +[XXX TODO - the Compiler backends may be broken when USE_ITHREADS is +enabled.] + =head2 Lexically scoped warning categories You can now control the granularity of warnings emitted by perl at a finer @@ -498,7 +545,7 @@ and the long double support. Perl subroutines with a prototype of C<($$)> and XSUBs in general can now be used as sort subroutines. In either case, the two elements to -be compared as passed as normal parameters in @_. See L. +be compared are passed as normal parameters in @_. See L. For unprototyped sort subroutines, the historical behavior of passing the elements to be compared as the global variables $a and $b remains diff --git a/sv.c b/sv.c index fddcd7e..7fa4514 100644 --- a/sv.c +++ b/sv.c @@ -6445,8 +6445,22 @@ Perl_ss_dup(pTHX_ PerlInterpreter *proto_perl) break; case SAVEt_FREEOP: ptr = POPPTR(ss,ix); - if (ptr && (((OP*)ptr)->op_private & OPpREFCOUNTED)) - TOPPTR(nss,ix) = any_dup(ptr, proto_perl); + if (ptr && (((OP*)ptr)->op_private & OPpREFCOUNTED)) { + /* these are assumed to be refcounted properly */ + switch (((OP*)ptr)->op_type) { + case OP_LEAVESUB: + case OP_LEAVESUBLV: + case OP_LEAVEEVAL: + case OP_LEAVE: + case OP_SCOPE: + case OP_LEAVEWRITE: + TOPPTR(nss,ix) = any_dup(ptr, proto_perl); + break; + default: + TOPPTR(nss,ix) = Nullop; + break; + } + } else TOPPTR(nss,ix) = Nullop; break; -- 2.7.4