NAME
WiringPi::API::WorkerThread - Handle for an ithread-based background worker
SYNOPSIS
use threads; # required for mechanism => 'thread'
use WiringPi::API qw(setup worker);
setup();
my $w = worker(sub {
# ... body sharing state with main ...
select(undef, undef, undef, 0.1);
}, { mechanism => 'thread' });
$w->stop; # sets the stop flag and joins the thread
DESCRIPTION
An object of this class is returned by "worker(\&body, \%opts)" in WiringPi::API under mechanism => 'thread', which runs the body in an ithread for shared-memory ergonomics on a threaded Perl.
You never construct one directly - worker() spawns the thread and hands you the handle.
It is a subclass of WiringPi::API::Worker, but the thread lifecycle is nothing like a fork's (no pid, no signal/waitpid), so this class overrides pid/running/stop/value. There are no pipe channels under thread mode - share a variable and serialise access with "pi_lock($key)" in WiringPi::API / "pi_unlock($key)" in WiringPi::API instead.
METHODS
pid
Threads have no process id, so this reports the thread id (tid) instead, keeping the handle interface uniform with the fork-based handles.
running
True while the thread is still alive; false once it has stopped. A once => 1 thread exits on its own, and running joins such a self-finished thread so it reflects reality.
stop
Set the cooperative stop flag (honoured at the next pass of the body) and join the thread. Idempotent. Returns 1.
value
Always undef under thread mode: there is no pipe channel, as shared-memory ergonomics replace it.
SEE ALSO
WiringPi::API, WiringPi::API::Worker.
AUTHOR
Steve Bertrand, <steveb@cpan.org>
COPYRIGHT AND LICENSE
Copyright (C) 2017-2026 by Steve Bertrand
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.18.2 or, at your option, any later version of Perl 5 you may have available.