Multi-Threading and Libmodbus

648 views
Skip to first unread message

Joe Wilcoxson

unread,
Jun 1, 2013, 9:14:56 AM6/1/13
to libm...@googlegroups.com
Hello everyone, I'm running in to a little issue. I am using libmodbus in a multithreaded c++ application. The main thread creates the modbus_mapping_t and modbus_new_rtu objects, then two worker threads get created. Thread A is the modbus_receive loop and Thread B writes out certain registers to a text file periodically when a certain modbus bit address is true. The application tends to get hung up in the logging thread, where even if the "start logging" modbus bit is true, it doesnt seem to recognize that until the server thread has been killed. I am relatively new to threading and I think I haven't properly set up the the two threads to share the modbus_mapping_t object. Does anyone have some examples of running libmodbus in a multithreaded application, sharing the modbus_mapping_t object between threads? Using Boost::Threads.

Stéphane Raimbault

unread,
Jun 3, 2013, 3:46:24 PM6/3/13
to libm...@googlegroups.com
Hi Joe,

You can use the same synchronisation techniques as usual in multithreaded application (mutex, condition variable, barrier or read/write lock).


2013/6/1 Joe Wilcoxson <joe.wi...@gmail.com>
Hello everyone, I'm running in to a little issue. I am using libmodbus in a multithreaded c++ application. The main thread creates the modbus_mapping_t and modbus_new_rtu objects, then two worker threads get created. Thread A is the modbus_receive loop and Thread B writes out certain registers to a text file periodically when a certain modbus bit address is true. The application tends to get hung up in the logging thread, where even if the "start logging" modbus bit is true, it doesnt seem to recognize that until the server thread has been killed. I am relatively new to threading and I think I haven't properly set up the the two threads to share the modbus_mapping_t object. Does anyone have some examples of running libmodbus in a multithreaded application, sharing the modbus_mapping_t object between threads? Using Boost::Threads.

--
Vous recevez ce message, car vous êtes abonné au groupe Google Groupes libmodbus.
Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le concernant, envoyez un e-mail à l'adresse libmodbus+...@googlegroups.com.
Pour plus d'options, visitez le site https://groups.google.com/groups/opt_out .
 
 

Reply all
Reply to author
Forward
0 new messages