Hello,
I'm currently implementing an application where I would like to make use of multiple threads (probably 3 threads, but maybe more in the future - it would be nice if I could create any number of threads based on a single parameter). Each thread will handle communication via Modbus RTU or TCP/IP (the application will be a communication gateway essentially), and each thread will need to have shared access to the same data structure. I've created a separate class to handle all Modbus communication in the background. Other wxWidgets frames will periodically access the public structure in this class to display the latest data.
Which wxWidgets classes/methods would you recommend that I use. Ideally, I'd like the threads to work as fast as possible and be able to implement some kind of data protection on the shared structure. I also don't need the threads to trigger any events in the other wxWidgets frames - just need them to work in the background and update the structure, while avoiding clashes in data access. Would wxThreadHelper do the job, or are there simpler/better ways of implementing this?
Many thanks,
Ksawery
Multi-threaded application Topic is solved
Re: Multi-threaded application
Just use wxThread for the threads and wxMutex/wxCriticalSection to protect access to shared resources.
Use the source, Luke!
Re: Multi-threaded application
Thank you, I'm currently following your suggestion, but haven't tested the application yet. Quick question - how does wxCiticalSection work exactly? As I understand, all threads trying to access the same memory location should use the same wxCriticalSection?
Regards,
Ksawery
Regards,
Ksawery
Re: Multi-threaded application
ubuntu 20.04, wxWidgets 3.2.1
Re: Multi-threaded application
Thanks.