NAME
threads::lite - Yet another threads library
VERSION
Version 0.021
SYNOPSIS
This module implements threads for perl. One crucial difference with normal threads is that the threads are entirely disconnected, except by message queues (channel). It thus facilitates a message passing style of multi-threading.
CLASS METHODS
spawn($options, $sub)
Spawn new threads. It will run $sub and send all monitoring processes it's return value. $options is a hashref that can contain the following elements.
- modules => [...]
-
Load the specified modules before running any code.
- pool_size => int
-
Create
pool_size
identical clones. The threads are cloned right after module load time, but before any code is run. - monitor => 0/1
-
If this is true, the calling process will monitor the newly spawned threads. Defaults to false.
- stack_size => int
-
The stack sze for the newly created threads. It defaults to 64 kiB.
$sub can be a function name or a subref. If it is a name, you must make sure the module it is in is loaded in the new thread. If it is a reference it will be serialized and sent to the new thread. This means that any enclosed variables will probability not work as expected.
FUNCTIONS
All these functions are exported by default.
Receiving functions
threads::lite exports by default three functions for receiving messages from the process mailbox. Each of them accepts matching patterns used to select those messages. Each of the elements in the pattern will be smartmatched against the appropriate element in the message. The message may contain more elements than the pattern, they will not be included in the matching.
receive(@pattern)
Return the first message matching pattern @pattern. If there is no such message in the queue, it blocks until a suitable message is received.
receive_nb(@pattern)
Return the first message matching pattern @pattern. If there is no such message in the queue, it returns an empty list (undef in scalar context).
receive_table( [@pattern] => action ]...)
Try to match each pattern to the message queue. The first successful pattern is used. If none of the patterns match any of the messages in the queue, it blocks until a suitable message is received.
Utility functions
self
Retreive the tid corresponding with the current thread.
AUTHOR
Leon Timmermans, <leont at cpan.org>
BUGS
This is an early development release, and is expected to be buggy and incomplete.
Please report any bugs or feature requests to bug-threads-lite at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=threads-lite. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc threads::lite
You can also look for information at:
RT: CPAN's request tracker
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
COPYRIGHT & LICENSE
Copyright 2009 Leon Timmermans, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.