Re: question on ev_loop_fork

2016-02-24 Thread Marc Lehmann
On Thu, Feb 25, 2016 at 09:50:20AM +0800, adream  wrote:
> It seems that ev_loop_fork didn't work as expected.
> Am I misunderstand the document?

Possibly - how _are_ you understanding it? :)

> So, can any guys shows me an example which would have different
> behavior if I call the ev_loop_fork or not?

If you want to use a loop before and after a fork, you need to tell libev
about it (or make it check for it). Not doing so is a bug, and finding out
how things then break (or not) is academic.

-- 
The choice of a   Deliantra, the free code+content MORPG
  -==- _GNU_  http://www.deliantra.net
  ==-- _   generation
  ---==---(_)__  __   __  Marc Lehmann
  --==---/ / _ \/ // /\ \/ /  schm...@schmorp.de
  -=/_/_//_/\_,_/ /_/\_\

___
libev mailing list
libev@lists.schmorp.de
http://lists.schmorp.de/mailman/listinfo/libev

Re: question on ev_loop_fork

2016-02-24 Thread Marc Lehmann
On Wed, Feb 24, 2016 at 09:22:15PM +0800, adream  wrote:
> hi
> I thought, if I didn't call the ev_loop_fork in the child, then the
> watcher in child wouldn't be triggered.

ev_loop_fork (or EVFLAG_FORKCHECK) are required for the event loop to
survive a fork. they don't do anything else.

not using them and forking *might* work in some circumstances, but *will*
fail in others.

so the choice between calling ev_loop_fork and not is "make the loop work"
vs. "undefined behaviour". the latter is a libev usage bug.

-- 
The choice of a   Deliantra, the free code+content MORPG
  -==- _GNU_  http://www.deliantra.net
  ==-- _   generation
  ---==---(_)__  __   __  Marc Lehmann
  --==---/ / _ \/ // /\ \/ /  schm...@schmorp.de
  -=/_/_//_/\_,_/ /_/\_\

___
libev mailing list
libev@lists.schmorp.de
http://lists.schmorp.de/mailman/listinfo/libev

Re: question on ev_loop_fork

2016-02-24 Thread adream
It seems that ev_loop_fork didn't work as expected.
Am I misunderstand the document?
So, can any guys shows me an example which would have different
behavior if I call the ev_loop_fork or not?
Thanks
Looking forward for any useful advice.

2016-02-24 21:22 GMT+08:00, adream :
> hi
> I thought, if I didn't call the ev_loop_fork in the child, then the
> watcher in child wouldn't be triggered.
> This is my code, I build the ev_loop with EVBACKEND_EPOLL and
> EVFLAG_NOENV flags, so there is no EVFLAG_FORKCHECK flag, then I comment
> the ev_loop_fork call in the child. if everything goes well, I thought the
> child will not trigger the timeout callback function. but actually, the
> output is something like this:
> 4980 fork 4981
> time out at 4980
> time out at 4981
>  it means that the watchers also has been triggered in the child.
>
>
>
>
> #include
> #include
> #include
>
> void timeout_cb(EV_P_ ev_timer *w,int revents)
> {
> printf("time out at %d\n", getpid());
> ev_break(EV_A_ EVBREAK_ONE);
> }
>
> int main()
> {
> int ret;
> ev_timer timeout_watcher;
>
> struct ev_loop *loop = ev_default_loop(EVBACKEND_EPOLL | EVFLAG_NOENV);
>
> ev_timer_init(&timeout_watcher,timeout_cb,5.5,0.);
> ev_timer_start(loop,&timeout_watcher);
> ret = fork();
> if(ret>0) printf("%d fork %d\n",getpid(),ret);
> else if(ret==0)
> {
> //ev_loop_fork(EV_DEFAULT);
> }
> else return -1;
> ev_run(loop,0);
> return 0;
> }
>

___
libev mailing list
libev@lists.schmorp.de
http://lists.schmorp.de/mailman/listinfo/libev

question on ev_loop_fork

2016-02-24 Thread adream
hi
I thought, if I didn't call the ev_loop_fork in the child, then the
watcher in child wouldn't be triggered.
This is my code, I build the ev_loop with EVBACKEND_EPOLL and
EVFLAG_NOENV flags, so there is no EVFLAG_FORKCHECK flag, then I comment
the ev_loop_fork call in the child. if everything goes well, I thought the
child will not trigger the timeout callback function. but actually, the
output is something like this:
4980 fork 4981
time out at 4980
time out at 4981
 it means that the watchers also has been triggered in the child.




#include
#include
#include

void timeout_cb(EV_P_ ev_timer *w,int revents)
{
printf("time out at %d\n", getpid());
ev_break(EV_A_ EVBREAK_ONE);
}

int main()
{
int ret;
ev_timer timeout_watcher;

struct ev_loop *loop = ev_default_loop(EVBACKEND_EPOLL | EVFLAG_NOENV);

ev_timer_init(&timeout_watcher,timeout_cb,5.5,0.);
ev_timer_start(loop,&timeout_watcher);
ret = fork();
if(ret>0) printf("%d fork %d\n",getpid(),ret);
else if(ret==0)
{
//ev_loop_fork(EV_DEFAULT);
}
else return -1;
ev_run(loop,0);
return 0;
}
___
libev mailing list
libev@lists.schmorp.de
http://lists.schmorp.de/mailman/listinfo/libev