Re: Is POE thread safe?
I think you misunderstand. POE synchronously calls all event handlers. It's up to other modules or applications to introduce preemptive concurrency. As presented, the examples you've shown don't introduce preemptive concurrency, so there should be no problem with them accessing "shared" resources. -- Rocco Caputo - [email protected] On May 23, 2009, at 23:17, howard chen wrote: Hello, On Sun, May 24, 2009 at 4:00 AM, Rocco Caputo wrote: In this case, response_handler() is always synchronized. Thanks for reply. "In this case" do you mean in POE::Component::Client::HTTP or in generic POE handler? For example, if I create session this way... for (1..10) { POE::Session->create( inline_states => { _start=> \&handler_start, increment => \&handler_increment, _stop => \&handler_stop, } ); } Is the handlers - "handler_increment" also synchronized so my global object can be safely accessed? Thanks. Thanks.
Re: Is POE thread safe?
Hello,
On Sun, May 24, 2009 at 4:00 AM, Rocco Caputo wrote:
> In this case, response_handler() is always synchronized.
>
Thanks for reply.
"In this case" do you mean in POE::Component::Client::HTTP or in
generic POE handler?
For example, if I create session this way...
for (1..10) {
POE::Session->create(
inline_states => {
_start=> \&handler_start,
increment => \&handler_increment,
_stop => \&handler_stop,
}
);
}
Is the handlers - "handler_increment" also synchronized so my global
object can be safely accessed?
Thanks.
Thanks.
Re: Is POE thread safe?
In this case, response_handler() is always synchronized. -- Rocco Caputo - [email protected] On May 23, 2009, at 14:52, howard chen wrote: Hey, For example, in POE::Component::Client::HTTP (http://search.cpan.org/~rcaputo/POE-Component-Client-HTTP-0.88/lib/POE/Component/Client/HTTP.pm ), the default max_per_host is 4. So is it always safe to do the following? (i.e. is the handler "response_handler" synchronized?) my $obj = MyClass->new(); # has member variable $data; ... sub response_handler { $obj->{data} = RANDOM_NUM; print $obj->{data}; # should princt exactly the RANDOM_NUM above, not the other RANDOM_NUM set by other thread/process }
