Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
As pg found out in the threads Perl 5.8.2 thread is much worse and Perl 5.8.2 thread is worse - more findings from today, it is now confirmed that indeed you can not reliably detach threads on Win32 systems.

Since the root cause is now known, a workaround of the problem is now also easy to do. Which I've done in the form of a new module: Thread::Detach (also available from http://www.liz.nl/CPAN if it hasn't arrived on a CPAN mirror near you yet).

From the pod:

THEORY OF OPERATION
All of this happens on Windows only and if the version of the Perl executor is known to have the problem.

This module replaces the standard threads->detach method with another subroutine that just sets an internal flag to mark the thread as "detached".

Futhermore it uses Thread::Exit to register a subroutine that is executed after each thread is finished executing: this subroutine marks the thread as "done".

Lastly, it uses Thread::Exit to register a subroutine that is executed at the beginning of each thread: this subroutine reaps all the threads that were marked "done", hence providing the necessary cleanup.

Unfortunately, I have not been able to really test the module, as I don't do Windows myself. So I appreciate any bug reports, should there be any (which will undoubtedly be the case).

This module should allow you to run all your threaded applications that used threads->detach unchanged by adding -MThread::Detach to the command line, or by setting the PERL5OPT environment variable.

Liz


In reply to Can't detach threads on Windows: Thread::Detach 0.01 by liz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2024-03-28 12:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found