Discussion:
Ensuring parser thread is running without stopping the main thread ?
Mohit Chawla
2011-08-04 16:16:53 UTC
Permalink
Hi,

With an app that I am working, I can't stop the other threads to give
control to the parser thread ( add_message_callback ). Is there any
way to achieve this ?
Mohit Chawla
2011-08-04 16:18:12 UTC
Permalink
On Thu, Aug 4, 2011 at 9:46 PM, Mohit Chawla
Post by Mohit Chawla
With an app that I am working, I can't stop the other threads to give
control to the parser thread ( add_message_callback ). Is there any
way to achieve this ?
I meant keep the parser thread running as well apart from the other
main thread ?
Erik Elmore
2011-08-04 16:48:08 UTC
Permalink
I believe this is the way it already functions. When you create a
connection, it spawns the parser thread (which is separate from the main
thread at that point) and your callbacks are called within the context of
the parser thread. Nothing in the parser thread should be blocking your
main thread--however if a callback blocks when it is called, the parser
thread is effectively hung until the callback returns. This is why I
normally have my callbacks creating new threads so there is zero blockage of
the parser thread.

+=
Erik Elmore
Post by Mohit Chawla
On Thu, Aug 4, 2011 at 9:46 PM, Mohit Chawla
Post by Mohit Chawla
With an app that I am working, I can't stop the other threads to give
control to the parser thread ( add_message_callback ). Is there any
way to achieve this ?
I meant keep the parser thread running as well apart from the other
main thread ?
_______________________________________________
Xmpp4r-devel mailing list
https://mail.gna.org/listinfo/xmpp4r-devel
Mohit Chawla
2011-08-04 17:43:13 UTC
Permalink
Hello,
I believe this is the way it already functions.  When you create a
connection, it spawns the parser thread (which is separate from the main
thread at that point) and your callbacks are called within the context of
the parser thread.  Nothing in the parser thread should be blocking your
main thread--however if a callback blocks when it is called, the parser
thread is effectively hung until the callback returns.  This is why I
normally have my callbacks creating new threads so there is zero blockage of
the parser thread.
Thanks for the reply. But I am not sure if I follow. In pretty much
all the examples for xmpp4r, the main thread is put to sleep using
Thread.stop, and only then the callbacks work as expected, otherwise
the process shuts down. Can you give me snippets/examples to
illustrate your point ? Also if it helps in anyway, I put up the
question on stack overflow as well, yesterday:
http://stackoverflow.com/questions/6931096/scheduling-threads-without-stopping-one
Loading...