Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Callback between Threads

9 views
Skip to first unread message

davidp...@yahoo.com.au

unread,
Apr 26, 2009, 6:10:44 AM4/26/09
to
Hi Group,

I am attempting to write a program that has two threads using PThreads
in C++ on Mac OSX.

The main thread is a GUI. The second thread reads from a USB to
serial device with a blocked read.

I have been looking for an C++ OO and thread safe technique for the
USB thread to inform the GUI thread about the receipt of data or a
change in the RS232 signals.

Basically in my main function I start a thread that read from the USB
device. At the moment I an just writing the data read from the USB to
stdout to confirm that the USB code works okay.

From what I have read on the net is the best approach is to use a
callback.

Does anyone have a reference to simple an C++ OO example that might
explain how I can do this?

I am rather new to multi threaded applications and I would like to
understand the best technique to use.

Thanks

David


David Schwartz

unread,
Apr 27, 2009, 12:15:34 AM4/27/09
to
On Apr 26, 3:10 am, davidpryce...@yahoo.com.au wrote:

> The main thread is a GUI.  The second thread reads from a USB to
> serial device with a blocked read.
>
> I have been looking for an C++ OO and thread safe technique for the
> USB thread to inform the GUI thread about the receipt of data or a
> change in the RS232 signals.

Why? Why not just have the thread that already knows that data has
been received do whatever needs to be done when data is received?
What's the logic of handing the information off to another thread when
one perfectly good thread already has the information.

> From what I have read on the net is the best approach is to use a
> callback.

I'm not sure what you mean by a callback. If you must hand it off to
another thread, probably the best approach is to queue the object to
the list of events the GUI thread already handles. If the GUI thread
is event driven, just add a 'USB data received' event to its incoming
event queue.

DS

0 new messages