There several models how to do many tasks simultaneously in single app: event loop, threads, fork... Let's take event loop and fork. Is it has sense to use both in single app?
At a glance - yes, of course! Event loop require event handlers doesn't take too much time to execute, because while one handler working all other events waiting. And first solution which come in mind - fork long-running event handler in separate process.
But let's check this in deep...
For ex. app has a lot of installed timers, needed for different things. And it does fork. So, what should happens with these timers in child process? Is child should inherit all timers? Or clear all timers? Or inherit only some timers? Huh...
Usually, when we do fork in usual, linear app, we know app state at that point, and know how we should change it state after fork (close some FD, clear some signals, etc.). But in event loop-based app we usually don't know current app state good enough to do such things.
All code in event loop-based app usually in event handlers. So, fork also will be executed inside event handler. After return in child process - what code will be executed? Ok, let's do not return - but what about die/exceptions?
One more example. We use events to monitor some FD in epoll. Then we do fork. At first, child inherit epoll's FD, used to control epoll. At second, it inherit all FD used in parent process. At this point parent may start receiving unexpected and strange epoll events, because of several reasons.
Actually this question has nothing with perl, it's much more general.
I've tested Event and Event::Lib - both do nothing to handle fork, and even doesn't mention issues related to fork in documentation.
Perl6 will contain event loop in core... and I doesn't see how it can work around these issues.
Or... there no issues here at all, and I just misunderstand some concepts?
In reply to Event-based app and fork() by powerman
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |