Re: Thread & Serial port



Christophe ASSOUS wrote:

Hello,

I would want to create three thread, each reading and writing on a serial port at the same time.
Is it possible ? Would you have an idea on how doing the management of the serial port by the thread?

If you have already done it, I would be pleased you to send me information or source code about this topic. (cube6_2000 yahoo fr)

Hello Christophe,

what do you mean exactly... you want "2" threads for each serial device ?
and you want to read and write to the same serial device concurrently ?

anyway... sure you can handle serial ports in seperate threads using glib.

ask yourself if you want to use GMainLoop in those threads... or just do
`while (select (fds...))' in your created thread.

Also... think about your ipc... you'll need to tell your threads at some point
to do something... this ipc will also vary if you are going to use GMainLoop
(with a mainloop in your thread... you can use
g_idle_source_new()/g_source_attach()/g_source_set_callback() to trigger an
event in the thread... otherwise you can use pipe()/socket() or some such).

An interesting tip is that you can always call g_idle_add() from a thread and the idle function will be called in the main thread (where the original GMainLoop
is being run)... so data can safely be communicated back from the thread
this way.

Cheers,
                                         -Tristan




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]