Re: ev_timer problem

2008-07-09 Thread Marc Lehmann
On Mon, Jul 07, 2008 at 03:54:21PM +0300, vvvua [EMAIL PROTECTED] wrote:
 When ev_loop finishes to maintain all registered timers, it waits on  
 epoll, and epoll waits for events from sockets.
 When i register a new timer in the second thread, ev_loop still waits on  
 epoll...

Of course, this is not allowed.

 To resolve this problem i created a heartbeat timer in the main thread.

It's not a solution, your program will just crash at different times now.

Get a book about threads programming and elarn about race conditions, and how
to avoid them (e.g. by using a mutex). Also refer to the threads section in
the libev manual. In short, if you don't lock the loop yourself, then the only
thing you can do in another thread is to call ev_async_send.

 Another solution - is to set timeout on sockets read/write operations.

Not sure what that solves, but you need to understand thread programming
and use proper locking to avoid races, otherwise your program runs into
undefined behaviour (most likely, crashes).

This is all documented in the libev documentation, however.

-- 
The choice of a   Deliantra, the free code+content MORPG
  -==- _GNU_  http://www.deliantra.net
  ==-- _   generation
  ---==---(_)__  __   __  Marc Lehmann
  --==---/ / _ \/ // /\ \/ /  [EMAIL PROTECTED]
  -=/_/_//_/\_,_/ /_/\_\

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


2 problems with AnyEvent::DNS

2008-07-09 Thread Михаил Монашёв
Hi, Marc Lehmann.

First.

1. I create object AnyEvent::DNS:

 my $resolver = AnyEvent::DNS-new()

2. Resolve some hosts.

2. Fetch some urls asynchronously if it's host has been resolved.

3. remove AnyEvent::DNS object:

   undef $resolver;

4. I create new object AnyEvent::DNS. Resolve some host. And get
problem: some old watchers rise and run old callback function in new
environment.

Old watchers wasn't removed after undef $resolver; and continue
working. Why? Timeout dosn't work correctly in AnyEvent::DNS I think.
It dosn't remove watchers.


#! /usr/bin/perl
use strict;
use warnings;

use AnyEvent::DNS;

my $resolver = AnyEvent::DNS-new(timeout = [2], server =
[AnyEvent::Socket::parse_address('127.0.0.201')]);
my $cv = AnyEvent-condvar();
my $resolve_sub = sub {
warn mindmix.ru resolved\n;
};
$resolver-resolve('mindmix.ru', 'a', accept = [a], $resolve_sub);
my $timer = AnyEvent-timer(
after = 1,
cb = sub {
warn timeout for mindmix.ru\n;
$cv-send();
}
);
$cv-recv();

undef $timer;
undef $resolver; # here all watchers have to remove
undef $resolve_sub;
undef $cv;


$resolver = AnyEvent::DNS-new(timeout = [2], server =
[AnyEvent::Socket::parse_address('127.0.0.201')]);
$cv = AnyEvent-condvar();
my $resolve_sub2 = sub {
warn beon.ru resolved\n;
};
$resolver-resolve('google.com', 'a', accept = [a], $resolve_sub2);
$timer = AnyEvent-timer(
after = 3,
cb = sub {
warn timeout for beon.ru\n;
$cv-send();
}
);

$cv-recv();



timeout for mindmix.ru
mindmix.ru resolved
beon.ru resolved
timeout for beon.ru

Why mindmix.ru resolved appear after undef $resolver; ?



Second.

Also some memory leaks found. Just add

use Devel::Leak::Object qw(GLOBAL_bless);

and run script:

Tracked objects by class:
AnyEvent::DNS1
Config   1
Errno1

-- 
Michael

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


Re: 2 problems with AnyEvent::DNS

2008-07-09 Thread Marc Lehmann
[this is off-topic for libev but relates to one of my other projects,
namely AnyEvent - I have replied off-list]

-- 
The choice of a   Deliantra, the free code+content MORPG
  -==- _GNU_  http://www.deliantra.net
  ==-- _   generation
  ---==---(_)__  __   __  Marc Lehmann
  --==---/ / _ \/ // /\ \/ /  [EMAIL PROTECTED]
  -=/_/_//_/\_,_/ /_/\_\

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