in reply to Re^3: Scope of thread variable
in thread Scope of thread variable

Can you tell me how to use eval on this code?

Or

How can I restart thread a thread if it died with same thread Id?

# some code here.... for (0 ..3)) { my $thr = threads->create ( sub { worker(); } )->detach(); } # Master Thread while (1) { master(); }

Replies are listed 'Best First'.
Re^5: Scope of thread variable
by BrowserUk (Patriarch) on Apr 08, 2010 at 16:07 UTC
    Can you tell me how to use eval on this code?

    To achieve what?

    How can I restart thread a thread if it died with same thread Id?

    You cannot. Thread ids are allocated by the system and are not re-used.

    If you need a number within your threads that you assign, just pass it in as a parameter:

    for my number (0 ..3)) { my $thr = threads->create ( sub { my $numberPassedIn = shift; worker(); }, $number )->detach(); }

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      How does the master thread know if worker threads are alive and well?