in reply to multi-threaded questions

a) If I use an smp system on Linux, can I expect threads to run on different processors like kernel threads?
Assuming your Linux is using the right threading kernel/library, yes. ithreads is based on pthreads on most POSIX-like systems. Assuming the provided pthreads implementation is SMP capable, ithreads will be as well.

How exactly is the determination made which processor which thread runs on?
Thats a pthreads/OS kernel issue. I believe some platforms provide APIs to bind individual threads to run on specific CPUs, but I don't know that they're widely implemented.

One note about your app: 30 + 30 threads may appear to consume a lot of vmem on Linux (and Windows too). Consider tuning the default thread stack size to a small value (see Re: Use more threads. and the threads CPAN note).


Perl Contrarian & SQL fanboy

Replies are listed 'Best First'.
Re^2: multi-threaded questions
by btoovey (Novice) on Dec 08, 2006 at 16:32 UTC
    Thanks for your response! I will research how my distro handles pthreads.
Re^2: multi-threaded questions
by btoovey (Novice) on Dec 08, 2006 at 19:15 UTC
    Do you have an idea if I am doing the que stuff properly?
      See embedded comments:
      use Thread::Queue; # # Thread::Queue is already shared (in fact, # its just a shared array) # our $queue = Thread::Queue->new; sub thread_sub { while ($test == 0) { if (certain test is true) {$test = 1;} } # # Not certain of your intent here, but assuming you're # just trying to send some data to another thread, then # you just need to pass the data as a parameter; # Note that doing so will return immediately wo/ # any ack. from the recv'r. Also note that # if $action is a ref to something, then that # something must also be threads::shared # # {my $action = $queue->enqueue;} $queue->enqueue($action); } sub thread_sub1 { # # this is fine. # $action = $queue->dequeue; #??? totally lost here print "I am going to do your bidding master now that the test is + true\n"; }
      Blatant plug:

      If you need full duplex communications between threads, you might peek at Thread::Queue::Duplex or Thread::Queue::Multiplex.


      Perl Contrarian & SQL fanboy
        Thanks for your response. I dont even want to pass data to the other threads - I just want them to start moving at the calling of the first threads.

        Does the code need to change at all if looped as the original example suggests?

        Brian