Parallel::ThreadContext

Framework for easy creation of multithreaded Perl programs
Download

Parallel::ThreadContext Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Publisher Name:
  • Serge Tsafak
  • Publisher web site:
  • http://search.cpan.org/~tsafserge/

Parallel::ThreadContext Tags


Parallel::ThreadContext Description

Framework for easy creation of multithreaded Perl programs ThreadContext is a Perl module provides a framework and some utilities for easy creation of multithreaded Perl programs. It introduces and uses the concept of context based concurrent threads.A context specifies a kind of name and work space for thread execution and consists of a queue + threads working on that queue + locks used by threads working on that queue. User can freely define as many contexts as he wants depending on its application logic e.g. 'prefetch', 'decode', 'execute', ... In each context threads are performing concurrent similar jobs on the same queue.All threads in the same context represent a thread group. Of course a group can consist of one thread only. Resources locked in one context do not affect other contexts.SYNOPSIS use Parallel::ThreadContext; my $counter = 0; my $counter_ref = \$counter; sub op1 { my $job = shift @_; Parallel::ThreadContext::abortCurrentThread("I am tired of living") if ($job == 30); Parallel::ThreadContext::println("performing job $job in Context ".Parallel::ThreadContext::getContextName()); Parallel::ThreadContext::pauseCurrentThread(1); Parallel::ThreadContext::reserveLock("counterlock","computation"); $counter++; Parallel::ThreadContext::releaseLock("counterlock","computation"); } $Parallel::ThreadContext::debug = 1; print STDOUT Parallel::ThreadContext::version(); my $nbthreads = Parallel::ThreadContext::getNoProcessors(); if (defined $nbthreads) { $nbthreads *= 3; #3 threads per processor } else { $nbthreads = 3; } Parallel::ThreadContext::shareVariable($counter_ref); Parallel::ThreadContext::start(\&op1,,$nbthreads,"computation"); Parallel::ThreadContext::addJobsToQueue(,"computation"); Parallel::ThreadContext::pauseCurrentThread(2); Parallel::ThreadContext::addJobsToQueue(,"computation"); Parallel::ThreadContext::pauseCurrentThread(4); Parallel::ThreadContext::end("computation"); #would give a warning if queue in the context is still open (not finalized yet) Parallel::ThreadContext::addJobsToQueue(,"computation"); #warning since mentioned context does no longer exist Parallel::ThreadContext::addJobsToQueue(,"computation"); Parallel::ThreadContext::start(\&op1,[],1,"computation2"); Parallel::ThreadContext::finalizeQueue("computation2"); Parallel::ThreadContext::yieldRuntime("computation2"); Parallel::ThreadContext::end("computation2"); Parallel::ThreadContext::println("final counter value is $counter"); Requirements: · Perl


Parallel::ThreadContext Related Software