[openamq-dev] Regarding amq_client_session_wait
blog
blog at yankeeboysoftware.com
Wed Dec 19 12:15:08 CET 2007
On Wed, 2007-12-19 at 11:56 +0100, Martin Sustrik wrote:
> > This is the problem: the call to amq_client_session_wait is a blocking
> > call. Blocking calls prevent me from controlling my application. How
> > do I cleanly interrupt the blocking call ?
>
> Still not sure what the problem is. In your preferred code below the
> sem_wait is a blocking call. What's the difference between calling
> amq_client_session_wait to wait for a message and calling sem_wait?
>
> Martin
The difference is that I can signal the semaphore from elsewhere in my
code (or in the case of a named semaphore, from anywhere), and allow the
thread to exit cleanly. This would also allow me to close the session
and connection properly, and also clean up other resources.
>
> >>> thread_func()
> >>> {
> >>> semaphore sync("Unique_name");
> >>> initialize_semaphore(sync, NOT_SIGNALED);
> >>> amq_client_session_wait (session, sync); //non-blocking call
> >>>
> >>> semaphore_wait(sync);// blocks until signaled - very efficiently.
> >>> if(amq_client_session_basic_arrived_count (session))
> >>> {
> >>> while (content && run)
> >>> {
> >>> // process content
> >>> content = amq_client_session_basic_arrived (session);
> >>> }
> >>> }
> >>> else
> >>> {
> >>> // something else happened on the sync object
> >>> // perhaps the app wants the thread to shutdown,
> >>> // either way, we have fallen out of the blocking call
> >>> }
> >>> }
> _______________________________________________
> openamq-dev mailing list
> openamq-dev at lists.openamq.org
> http://lists.openamq.org/mailman/listinfo/openamq-dev
More information about the openamq-dev
mailing list