tagged release 0.6.4
[parrot.git] / src / pmc / parrotrunningthread.pmc
blobf1e4c1513087a3387a1d5b3ef938177a49fb2ad3
1 /*
2 Copyright (C) 2006-2008, The Perl Foundation.
3 $Id$
5 =head1 NAME
7 src/pmc/parrotrunningthread.pmc -- Represents a running Parrot Thread.
9 =head1 DESCRIPTION
11 This type represents a running parrot thread.
13 It provides the following methods:
14     - join
15     - detach
16     - kill
18 Note that a running thread object becomes invalid when a thread
19 finishes while detached or joined. Further operations on the
20 object may have unexpected behavior, such as manipulating an
21 unrelated thread.
23 =head2 Methods
25 =over 4
27 =cut
31 #include "parrot/parrot.h"
32 #include "parrot/embed.h"
34 pmclass ParrotRunningThread no_ro {
38 =item C<void init()>
40 Create a new, invalid handle to a running thread.
42 =cut
46     VTABLE void init() {
47         PMC_int_val(SELF) = -1;
48     }
52 =item C<void init_pmc(PMC *tid)>
54 Create a new running thread referring to the thread with
55 the Thread ID specified in C<tid>.
57 =cut
61     VTABLE void init_pmc(PMC *tid) {
62         PMC_int_val(SELF) = VTABLE_get_integer(INTERP, tid);
63     }
67 =item C<INTVAL get_integer()>
69 Return the thread ID of this thread.
71 =cut
75     VTABLE INTVAL get_integer() {
76         return PMC_int_val(SELF);
77     }
81 =item C<void set_integer_native(INTVAL new_tid)>
83 Change the thread ID we refer to to C<new_tid>.
87     VTABLE void set_integer_native(INTVAL new_tid) {
88         PMC_int_val(SELF) = new_tid;
89     }
92 =item C<METHOD join()>
94 Join the thread, returning whatever its main method returns.
96 =cut
99     METHOD join() {
100         PMC *ret          = pt_thread_join(INTERP, PMC_int_val(SELF));
102         /* invalidate self */
103         PMC_int_val(SELF) = -1;
105         RETURN(PMC *ret);
106     }
110 =item C<METHOD detach()>
112 Detach the thread so it cannot be joined and will free its
113 resources immediatelly when it exits.
115 =cut
119     METHOD detach() {
120         pt_thread_detach(PMC_int_val(SELF));
121     }
125 =item C<METHOD kill()>
127 Terminate a running thread.
129 =cut
133     METHOD kill() {
134         pt_thread_kill(PMC_int_val(SELF));
135     }
141 =back
143 =cut
148  * Local variables:
149  *   c-file-style: "parrot"
150  * End:
151  * vim: expandtab shiftwidth=4:
152  */