2 Copyright (C) 2001-2007, The Perl Foundation.
7 src/pmc/parrotthread.pmc - Threaded Interpreter
11 ParrotThread extends ParrotInterpreter to provide a threaded interpreter
14 new P2, "ParrotThread" # create new threaded interp
15 find_method P0, P2, "thread3" # thread-run function
16 find_global P5, "_th1" # locate thread function
19 set I0, P2 # get thread id
25 thread3 # start thread of type 1..3
39 #include "parrot/parrot.h"
40 #include "parrot/embed.h"
43 * can't do multi-threaded DOD/GC yet
44 * XXX a quick hack to pass the few tests
47 stop_GC(Interp *parent, Interp *thread)
50 Parrot_block_DOD(parent);
51 Parrot_block_DOD(thread);
52 Parrot_block_GC(parent);
53 Parrot_block_GC(thread);
57 /* XXX FIXME probably not the best interface [see also list post of
61 static INTVAL do_thread_run(PARROT_INTERP, PMC *thread,
62 INTVAL clone_flags, PMC *sub, PMC *args) {
63 INTVAL tid = VTABLE_get_integer(interp, thread);
65 clone_interpreter(PMC_data_typed(thread, Parrot_Interp),
68 interp->flags &= ~PARROT_THR_COPY_INTERP; /* XXX */
69 pt_thread_run(interp, thread, sub, args);
71 pmc_reuse(interp, thread, enum_class_ParrotRunningThread, 0);
73 PObj_active_destroy_CLEAR(thread);
74 PObj_custom_mark_CLEAR(thread);
75 PMC_int_val(thread) = tid;
80 static INTVAL do_thread_run_clone_default(PARROT_INTERP,
81 PMC *thread, PMC *sub, PMC *args) {
82 return do_thread_run(interp, thread, PARROT_CLONE_DEFAULT, sub, args);
86 pmclass ParrotThread extends ParrotInterpreter need_ext no_ro {
90 =item C<thread_id = thread.'run'(CLONE_FLAGS, sub, args...)>
92 Run the thread. This object is morphed into an appropriate
93 ParrotRunningThread PMC. The CLONE_FLAGS are or'd together values
94 taken from C<cloneflags.pasm>.
96 =item C<thread_id = thread.'run_clone'(sub, args...)>
98 Equivalent to calling run with PARROT_CLONE_DEFAULT.
105 const int typ = enum_class_ParrotThread;
108 register_nci_method(INTERP, typ,
109 F2DPTR(do_thread_run), "run", "IJOIP@");
111 /* XXX appropriate name given that this won't clone globals? */
112 register_nci_method(INTERP, typ,
113 F2DPTR(do_thread_run_clone_default), "run_clone", "IJOP@");
121 Initializes the thread.
128 /* protect interpreter creation and list handling */
129 LOCK(interpreter_array_mutex);
132 pt_add_to_interpreters(INTERP, PMC_data_typed(SELF, Parrot_Interp));
134 UNLOCK(interpreter_array_mutex);
136 /* can't allow DOD runs for now */
137 stop_GC(INTERP, PMC_data_typed(SELF, Parrot_Interp));
142 =item C<void init_pmc(PMC *parent)>
144 Create a new thread by cloning the passed interpreter.
150 VTABLE void init_pmc(PMC *parent) {
151 LOCK(interpreter_array_mutex);
154 pt_add_to_interpreters(PMC_data_typed(parent, Parrot_Interp),
155 PMC_data_typed(SELF, Parrot_Interp));
157 UNLOCK(interpreter_array_mutex);
159 /* can't allow DOD runs for now */
160 stop_GC(INTERP, PMC_data_typed(SELF, Parrot_Interp));
170 2003.12.18 leo initial review.
178 * c-file-style: "parrot"
180 * vim: expandtab shiftwidth=4: