how to 'return immediately' ?

Fulko Hew fulko.hew at gmail.com
Fri Dec 7 21:47:55 CET 2012


I'm not sure how to adequately describe the problem I'm having but...

My application interacts with other remote programs via TCP
as both a server and a client.

b) When the app doesn't have an object it creates one,
   does a push_write(),
   then returns the blessed object.
c) the caller/mainline records that object
d) go to step 1

The pseudo code is:

sub new {
   my $obj = bless {}, $class;
   $connection->push_write(...);
   return $obj;
}

sub a_read_handler {
  $row = new(...) unless defined $row;
  ...
}

The way I can explain my symptoms are that I have a race condition where...

I call new() alot (to create many objects), which means that push_write()
has been called alot...

Calling push_write() eventually defers the returning of the object being
created [because the outbound queue is backing up and its trying to empty
it]
to the point where my mainline, since it hasn't received the returned
object yet, hasn't saved it, and so when it performs its test, and doesn't
find it, and calls new() again [for the same 'thing'].

[Because of the other interactions between my various apps,
a 'system messaging corruption' would then occur.]

Conclusion: It seems like calling push_write() can allow my
            read_handler to run before the new has returned.

If this is indeed possible...
  'is there any way I can force the push_write to be asynchronous,
  to ensure the return happens _first_?'

[I've read about 'guard', but I don't know if that's what I
should use, or is there something else?]

TIA
Fulko
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.schmorp.de/pipermail/anyevent/attachments/20121207/d8720a5e/attachment.html>


More information about the anyevent mailing list