cvsuser     03/12/26 04:50:06

  Modified:    classes  parrotinterpreter.pmc parrotthread.pmc
               examples/assembly thr-primes.imc
               include/parrot interpreter.h thread.h
               src      thread.c
               t/op     interp.t
               t/pmc    tqueue.t
  Log:
  parrot-threads-14
  * support for different thread types
  * renamed thread run methods to thread1..3
  
  Revision  Changes    Path
  1.20      +14 -3     parrot/classes/parrotinterpreter.pmc
  
  Index: parrotinterpreter.pmc
  ===================================================================
  RCS file: /cvs/public/parrot/classes/parrotinterpreter.pmc,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -w -r1.19 -r1.20
  --- parrotinterpreter.pmc     22 Dec 2003 15:31:58 -0000      1.19
  +++ parrotinterpreter.pmc     26 Dec 2003 12:49:48 -0000      1.20
  @@ -1,7 +1,7 @@
   /* parrotinterpreter.pmc
    *  Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
    *  CVS Info
  - *     $Id: parrotinterpreter.pmc,v 1.19 2003/12/22 15:31:58 leo Exp $
  + *     $Id: parrotinterpreter.pmc,v 1.20 2003/12/26 12:49:48 leo Exp $
    *  Overview:
    *     These are the vtable functions for the ParrotInterpreter base class
    *  Data Structure and Algorithms:
  @@ -20,7 +20,6 @@
   #include "parrot/embed.h"
   #include <assert.h>
   
  -void clone_interpreter(PMC* dest, PMC* self);
   /*
    * copy / clone interpreter registers
    * all resources are created in the destination interpreter
  @@ -134,8 +133,20 @@
   
           method_table = pmc_new(INTERP, enum_class_PerlHash);
   
  +        /*
  +         * thread start methods for threads type 1..3
  +         * TODO fix signature, when P2/P5 object issues are clarified
  +         */
  +        enter_nci_method(INTERP, method_table,
  +                         F2DPTR(pt_thread_run_1), "thread1", "vIPP");
  +        enter_nci_method(INTERP, method_table,
  +                         F2DPTR(pt_thread_run_2), "thread2", "vIPP");
           enter_nci_method(INTERP, method_table,
  -                         F2DPTR(pt_thread_run), "thread", "vIPP");
  +                         F2DPTR(pt_thread_run_3), "thread3", "vIPP");
  +
  +        /*
  +         * TODO unify and fix signatures
  +         */
           enter_nci_method(INTERP, method_table,
                            F2DPTR(pt_thread_yield), "yield", "v");
           enter_nci_method(INTERP, method_table,
  
  
  
  1.6       +9 -5      parrot/classes/parrotthread.pmc
  
  Index: parrotthread.pmc
  ===================================================================
  RCS file: /cvs/public/parrot/classes/parrotthread.pmc,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -w -r1.5 -r1.6
  --- parrotthread.pmc  21 Dec 2003 10:15:08 -0000      1.5
  +++ parrotthread.pmc  26 Dec 2003 12:49:48 -0000      1.6
  @@ -1,7 +1,7 @@
   /* parrotthread.pmc
    *  Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
    *  CVS Info
  - *     $Id: parrotthread.pmc,v 1.5 2003/12/21 10:15:08 leo Exp $
  + *     $Id: parrotthread.pmc,v 1.6 2003/12/26 12:49:48 leo Exp $
    *  Overview:
    *     ParrotThread is a threaded ParrotInterpreter subclass
    *  Data Structure and Algorithms:
  @@ -10,16 +10,20 @@
    *  Notes:
    *     Additionally to ParrotInterpreter a ParrotThread supports:
    *
  - *     getinterp P2             # get current interpreter
  + *     new P0, .ParrotThread     # create new threaded interp
  + *     getinterp P2
    *     new P0, .ParrotThread, P2        # create thread P0 from interp P2
    *     set I0, P0               # get thread id
    *
    *     and these methods:
    *
  - *     thread ()
  + *     thread1
  + *     thread2
  + *     thread3                   # start thread of type 1..3
    *     join
    *     detach
    *     yield
  + *     kill
    *
    *  References:
    */
  
  
  
  1.3       +2 -2      parrot/examples/assembly/thr-primes.imc
  
  Index: thr-primes.imc
  ===================================================================
  RCS file: /cvs/public/parrot/examples/assembly/thr-primes.imc,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -w -r1.2 -r1.3
  --- thr-primes.imc    20 Dec 2003 11:56:31 -0000      1.2
  +++ thr-primes.imc    26 Dec 2003 12:49:51 -0000      1.3
  @@ -59,7 +59,7 @@
       $P2 = new PerlInt
       $P2 = 2
       .sym pmc Thread_new
  -    find_method Thread_new, kid, "thread"
  +    find_method Thread_new, kid, "thread3"
       .pcc_begin prototyped
       .arg kid
       .arg Check_num
  @@ -137,7 +137,7 @@
   #       29                $kid = new threads(\&check_num, $downstream, $num);
       kid = new ParrotThread
       .sym pmc Thread_new
  -    find_method Thread_new, kid, "thread"
  +    find_method Thread_new, kid, "thread3"
       .pcc_begin prototyped
       .arg kid
       .arg sub
  
  
  
  1.111     +21 -10    parrot/include/parrot/interpreter.h
  
  Index: interpreter.h
  ===================================================================
  RCS file: /cvs/public/parrot/include/parrot/interpreter.h,v
  retrieving revision 1.110
  retrieving revision 1.111
  diff -u -w -r1.110 -r1.111
  --- interpreter.h     22 Dec 2003 15:32:00 -0000      1.110
  +++ interpreter.h     26 Dec 2003 12:49:53 -0000      1.111
  @@ -1,7 +1,7 @@
   /* interpreter.h
    *  Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
    *  CVS Info
  - *     $Id: interpreter.h,v 1.110 2003/12/22 15:32:00 leo Exp $
  + *     $Id: interpreter.h,v 1.111 2003/12/26 12:49:53 leo Exp $
    *  Overview:
    *     The interpreter api handles running the operations
    *  Data Structure and Algorithms:
  @@ -22,11 +22,20 @@
       PARROT_DEBUG_FLAG    = 0x01,  /* We're debugging */
       PARROT_TRACE_FLAG    = 0x02,  /* We're tracing execution */
       PARROT_BOUNDS_FLAG   = 0x04,  /* We're tracking byte code bounds */
  -    PARROT_PROFILE_FLAG  = 0x08,  /* We're gathering profile information */
  -    PARROT_GC_DEBUG_FLAG = 0x10,  /* We're debugging memory management */
  +    PARROT_PROFILE_FLAG     = 0x08,  /* gathering profile information */
  +    PARROT_GC_DEBUG_FLAG    = 0x10,  /* debugging memory management */
  +
       PARROT_EXTERN_CODE_FLAG = 0x100,    /* reusing anothers interps code */
       PARROT_DESTROY_FLAG  = 0x200,  /* the last interpreter shall cleanup */
  -    PARROT_IS_THREAD     = 0x400   /* true if interpreter is a thread */
  +
  +    PARROT_IS_THREAD        = 0x1000, /* interpreter is a thread */
  +    PARROT_THR_COPY_INTERP  = 0x2000, /* thread start copies interp state */
  +    PARROT_THR_THREAD_POOL  = 0x4000, /* type3 threads */
  +
  +    PARROT_THR_TYPE_1 = PARROT_IS_THREAD,
  +    PARROT_THR_TYPE_2 = PARROT_IS_THREAD | PARROT_THR_COPY_INTERP,
  +    PARROT_THR_TYPE_3 = PARROT_IS_THREAD | PARROT_THR_COPY_INTERP |
  +                        PARROT_THR_THREAD_POOL
   } Parrot_Interp_flag;
   
   /* &end_gen */
  @@ -321,6 +330,8 @@
   void *init_jit(Parrot_Interp interpreter, opcode_t *pc);
   void dynop_register(Parrot_Interp interpreter, PMC* op_lib);
   void do_prederef(void **pc_prederef, Parrot_Interp interpreter, int type);
  +
  +void clone_interpreter(PMC* dest, PMC* self);
   
   #else
   
  
  
  
  1.15      +5 -1      parrot/include/parrot/thread.h
  
  Index: thread.h
  ===================================================================
  RCS file: /cvs/public/parrot/include/parrot/thread.h,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -w -r1.14 -r1.15
  --- thread.h  24 Dec 2003 10:43:08 -0000      1.14
  +++ thread.h  26 Dec 2003 12:49:53 -0000      1.15
  @@ -1,7 +1,7 @@
   /* thread.h
    *  Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
    *  CVS Info
  - *     $Id: thread.h,v 1.14 2003/12/24 10:43:08 leo Exp $
  + *     $Id: thread.h,v 1.15 2003/12/26 12:49:53 leo Exp $
    *  Overview:
    *     This is the api header for the thread primitives
    *  Data Structure and Algorithms:
  @@ -106,6 +106,10 @@
    * thread.c interface functions
    */
   int  pt_thread_run(Parrot_Interp, PMC* dest_interp, PMC* sub);
  +int  pt_thread_run_1(Parrot_Interp, PMC* dest_interp, PMC* sub);
  +int  pt_thread_run_2(Parrot_Interp, PMC* dest_interp, PMC* sub);
  +int  pt_thread_run_3(Parrot_Interp, PMC* dest_interp, PMC* sub);
  +
   void pt_thread_prepare_for_run(Parrot_Interp d, Parrot_Interp s);
   void pt_clone_code(Parrot_Interp d, Parrot_Interp s);
   void pt_add_to_interpreters(Parrot_Interp first, Parrot_Interp new_interp);
  
  
  
  1.10      +45 -4     parrot/src/thread.c
  
  Index: thread.c
  ===================================================================
  RCS file: /cvs/public/parrot/src/thread.c,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -w -r1.9 -r1.10
  --- thread.c  24 Dec 2003 10:43:12 -0000      1.9
  +++ thread.c  26 Dec 2003 12:49:55 -0000      1.10
  @@ -1,7 +1,7 @@
   /* thread.c
    *  Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
    *  CVS Info
  - *     $Id: thread.c,v 1.9 2003/12/24 10:43:12 leo Exp $
  + *     $Id: thread.c,v 1.10 2003/12/26 12:49:55 leo Exp $
    *  Overview:
    *     Thread handling stuff
    *  Data Structure and Algorithms:
  @@ -86,8 +86,6 @@
       d->pmc_reg.registers[1] = ret_c;
   }
   
  -void clone_interpreter(PMC* dest, PMC* self);
  -
   /*
    * ParrotThread emthods
    *
  @@ -101,7 +99,15 @@
   
       PMC *parent = VTABLE_get_pmc_keyed_int(interp, interp->iglobals,
                   IGLOBALS_INTERPRETER);
  +
  +    /*
  +     * TODO check if thread flags are consistent
  +     */
  +    if (interp->flags & PARROT_THR_COPY_INTERP)
       clone_interpreter(dest_interp, parent);
  +    /*
  +     * TODO thread pools
  +     */
   
       dest_interp->cache.struct_val = sub->cache.struct_val;
       pt_thread_prepare_for_run(interpreter, interp);
  @@ -120,6 +126,41 @@
       THREAD_CREATE_JOINABLE(interpreter->thread_data->thread,
               thread_func, dest_interp);
       return 0;
  +}
  +
  +/*
  + * run a type 1 thread
  + * nothing is shared, both interpreters are free running
  + * w/o any communication
  + */
  +
  +int
  +pt_thread_run_1(Parrot_Interp interp, PMC* dest_interp, PMC* sub)
  +{
  +    interp->flags |= PARROT_THR_TYPE_1;
  +    return pt_thread_run(interp, dest_interp, sub);
  +}
  +
  +/*
  + * run a type 2 thread
  + * no shared variables, threads are communicating by sending messages
  + */
  +int
  +pt_thread_run_2(Parrot_Interp interp, PMC* dest_interp, PMC* sub)
  +{
  +    interp->flags |= PARROT_THR_TYPE_2;
  +    return pt_thread_run(interp, dest_interp, sub);
  +}
  +
  +/*
  + * run a type 3 thread
  + * threads may have shared variables and are managed in a thread pool
  + */
  +int
  +pt_thread_run_3(Parrot_Interp interp, PMC* dest_interp, PMC* sub)
  +{
  +    interp->flags |= PARROT_THR_TYPE_3;
  +    return pt_thread_run(interp, dest_interp, sub);
   }
   
   /*
  
  
  
  1.25      +40 -11    parrot/t/op/interp.t
  
  Index: interp.t
  ===================================================================
  RCS file: /cvs/public/parrot/t/op/interp.t,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -w -r1.24 -r1.25
  --- interp.t  19 Dec 2003 16:42:41 -0000      1.24
  +++ interp.t  26 Dec 2003 12:50:00 -0000      1.25
  @@ -1,6 +1,6 @@
   #! perl -w
   
  -use Parrot::Test tests => 14;
  +use Parrot::Test tests => 15;
   
   output_is(<<'CODE', <<'OUTPUT', "runinterp - new style");
        new P0, .ParrotInterpreter
  @@ -242,7 +242,7 @@
   OUTPUT
   
   SKIP: {
  -  skip("No thread config yet" ,3) unless $^O eq 'linux';
  +  skip("No thread config yet" ,4) unless $^O eq 'linux';
   
   output_is(<<'CODE', <<'OUTPUT', "interp identity");
       getinterp P2
  @@ -262,8 +262,42 @@
   ok 2
   OUTPUT
   
  +output_is(<<'CODE', <<'OUTPUT', "thread type 1");
  +    set I5, 10
  +    #
  +    # set regs P5 = thread-interp, P6 = sub
  +    find_global P6, "_foo"
  +    new P5, .ParrotThread
  +    find_method P0, P5, "thread1"
  +    invoke   # start the thread
  +
  +    sleep 1
  +    print "main "
  +    print I5
  +    print "\n"
  +    # get tid of thread
  +    set I5, P5
  +    # wait for it
  +    find_method P0, P5, "join"
  +    invoke
  +    end
  +
  +.pcc_sub _foo:
  +    # check if vars are fresh
  +    inc I5
  +    print "thread "
  +    print I5
  +    print "\n"
  +    invoke P1        # ret and be done with thread
  +
  +# output from threads could be reversed
  +CODE
  +thread 1
  +main 10
  +OUTPUT
  +
   
  -output_is(<<'CODE', <<'OUTPUT', "thread 1");
  +output_is(<<'CODE', <<'OUTPUT', "thread type 2");
       set I5, 1
       set S5, " interp\n"
       new P7, .PerlString
  @@ -276,13 +310,10 @@
       find_global P6, "_foo"
       print "ok 2\n"
       new P5, .ParrotThread
  -    find_method P0, P5, "thread"
  +    find_method P0, P5, "thread2"
       invoke   # start the thread
   
  -    print P7
  -    print I5
  -    print S5
  -    sleep 1
  +    sleep 1  # now the thread should run
       print P7
       print I5
       print S5
  @@ -312,11 +343,9 @@
       print "\n"
       invoke P1        # ret and be done with thread
   
  -# output from threads could be reversed
   CODE
   ok 1
   ok 2
  -from 1 interp
   hello from 2 thread
   ParrotThread tid 1
   Sub
  @@ -331,7 +360,7 @@
       print "start "
       print I10
       print "\n"
  -    find_method P0, P5, "thread"
  +    find_method P0, P5, "thread3"
       invoke   # start the thread
       sleep 1
   
  
  
  
  1.3       +1 -1      parrot/t/pmc/tqueue.t
  
  Index: tqueue.t
  ===================================================================
  RCS file: /cvs/public/parrot/t/pmc/tqueue.t,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -w -r1.2 -r1.3
  --- tqueue.t  19 Dec 2003 14:07:47 -0000      1.2
  +++ tqueue.t  26 Dec 2003 12:50:06 -0000      1.3
  @@ -46,7 +46,7 @@
   
       new P5, .ParrotThread
       find_global P6, "_foo"
  -    find_method P0, P5, "thread"
  +    find_method P0, P5, "thread3"
       invoke   # start the thread
       set I5, P5
       getinterp P2
  
  
  

Reply via email to