Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: fork & END

by xdg (Monsignor)
on Sep 07, 2005 at 11:53 UTC ( [id://489836]=note: print w/replies, xml ) Need Help??


in reply to fork & END

Regarding your afterthought: I don't really like END blocks, particularly for modules, because they create another form of the "action at a distance" problem. I would prefer that any module that relies on them say so explictly and with appropriate warnings. I know they are useful in some cases -- but they can easily create problems for downstream users, as you've discovered.

The other thing you asked about is fork. Anytime one is trying to do concurrency, whether forks or threads, a whole host of new concerns inevitably arise. I think it's very important to think through exactly what side effects might arise through concurrency, particularly around cleanup/teardown code. END blocks are just one example. What about object destructors? Assuming that one is finished with some resource is one thread/process may or may not be OK depending on the nature of the cleanup. It may be useful to store $$ in BEGIN as a way of limiting destruction action to the parent process/thread, but it may also be useless in many cases.

Ultimately, I think END should be an infrequent tool, but I think that the onus is on those forking/threading to anticipate side effects and code to prevent them. What makes END so insidious is that one can't defuse it, whereas one could always wrap a misbehaving DESTROY method to call the original only if it has been called from within the parent process.

-xdg

Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://489836]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (6)
As of 2025-07-17 11:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.