Question
Is a shared object a good way to communicate state information between a parent process and one or more worker threads? I was imagining either one of two ways to communicate progress of work done - for example - by a worker thread:
- Variables passed by reference to the worker thread
std::atomic<int> percentageProgress; std::thread worker_thread(someFunctionCall, std::ref(percentageProgress));
- Object - with state variables as object members - passed by reference
std::atomic<SharedStateObj> mySharedStateObj; std::thread worker_thread(someFunctionCall, std::ref(mySharedStateObj));
Additional Thoughts:
If I declare the SharedStateObj member variables as static and initialize the mySharedStateObj in the main process how will this change a mySharedStateObj_worker object that is initialized inside a worker thread?
Language: C++11 System: Nvidia Jetson Operating System: Linux Ubuntu 16.04
Aucun commentaire:
Enregistrer un commentaire