| 1 | package SPVM::Thread; | ||
| 2 | |||
| 3 | 1 | our $VERSION = "0.012"; | |
| 4 | |||
| 5 | 1 | 1; | |
| 6 | |||
| 7 | =head1 Name | ||
| 8 | |||
| 9 | SPVM::Thread - Native Thread | ||
| 10 | |||
| 11 | =head1 Description | ||
| 12 | |||
| 13 | Thread class in L<SPVM> manipulates native threads. | ||
| 14 | |||
| 15 | This class is a binding of L<std::thread in C++|https://en.cppreference.com/w/cpp/thread/thread>. | ||
| 16 | |||
| 17 | =head1 Usage | ||
| 18 | |||
| 19 | use Thread; | ||
| 20 | |||
| 21 | my $results = [0]; | ||
| 22 | my $thread = Thread->new([$results : int[]] method : void () { | ||
| 23 | $results->[0] = 5; | ||
| 24 | }); | ||
| 25 | |||
| 26 | $thread->join; | ||
| 27 | |||
| 28 | =head1 Fields | ||
| 29 | |||
| 30 | =head2 task | ||
| 31 | |||
| 32 | C<has task : L<Callback|SPVM::Callback>;> | ||
| 33 | |||
| 34 | A task exceuted by a thread. | ||
| 35 | |||
| 36 | =head2 caller_info | ||
| 37 | |||
| 38 | C<has caller_info : L<CallerInfo|SPVM::CallerInfo>;> | ||
| 39 | |||
| 40 | Thead caller information. | ||
| 41 | |||
| 42 | =head1 Class Methods | ||
| 43 | |||
| 44 | =head2 new | ||
| 45 | |||
| 46 | C<static method new : L<Thread|SPVM::Thread> ($task : L<Callback|SPVM::Callback>);> | ||
| 47 | |||
| 48 | Creates a new native thread and run the task $task on it. | ||
| 49 | |||
| 50 | And creates a new L<Thread|SPVM::Thread> object and returns it. | ||
| 51 | |||
| 52 | All maskable signals are blocked in the newly created thread. | ||
| 53 | |||
| 54 | =head1 Instance Methods | ||
| 55 | |||
| 56 | =head2 join | ||
| 57 | |||
| 58 | C<method join : void ();> | ||
| 59 | |||
| 60 | Waits for the thread to finish. | ||
| 61 | |||
| 62 | =head2 get_id | ||
| 63 | |||
| 64 | C<method get_id : L<Thread::ID|SPVM::Thread::ID> ();> | ||
| 65 | |||
| 66 | Gets the thread ID. | ||
| 67 | |||
| 68 | =head1 Repository | ||
| 69 | |||
| 70 | L<SPVM::Thread - Github|https://github.com/yuki-kimoto/SPVM-Thread> | ||
| 71 | |||
| 72 | =head2 See Also | ||
| 73 | |||
| 74 | =over 2 | ||
| 75 | |||
| 76 | =item * L<Thread::ThisThread|SPVM::Thread::ThisThread> | ||
| 77 | |||
| 78 | =item * L<Thread::ID|SPVM::Thread::ID> | ||
| 79 | |||
| 80 | =item * L<std::thread in C++|https://en.cppreference.com/w/cpp/thread/thread> | ||
| 81 | |||
| 82 | =back | ||
| 83 | |||
| 84 | =head1 Author | ||
| 85 | |||
| 86 | Yuki Kimoto C<kimoto.yuki@gmail.com> | ||
| 87 | |||
| 88 | =head1 Copyright & License | ||
| 89 | |||
| 90 | Copyright 2022-2022 Yuki Kimoto, all rights reserved. | ||
| 91 | |||
| 92 | This program is free software; you can redistribute it and/or modify it | ||
| 93 | under the same terms as Perl itself. | ||
| 94 |