LOGIN






Welcome, Guest

Multithreading
(1 viewing) (1) Guest
  • Page:
  • 1

TOPIC: Multithreading

Multithreading 1 year, 3 months ago #22014

Hi

I'm trying to desing a module where two threads (two member methods of my module class) need to have access to the same variables (private member variables of my object of the module class). I'd like the second thread to be called by the first one. The first one's just called by a python script via a proxy.

I tried to do this as follows (based on what I found in the official documenation):
cf.
users.aldebaran-robotics.com/docs/site_e...work/monitoring.html
users.aldebaran-robotics.com/docs/site_e..._robot_software.html

// C++
// in firstFunction(..., const int& parameter, ...)
...
int threadID = getProxy("myModule")->pCall("secondFunction", parameter);
// alternatively: int threadID = getProxy(getName())->pCall("secondFunction", parameter);  
...
return 0;


I also tried the following:
// C++
// in firstFunction(..., const int& parameter, ...)
...
int threadID = getParentBroker->getProxy("myModule")->pCall("secondFunction", parameter);
// alternatively: int threadID = getParentBroker->getProxy(getName())->pCall("secondFunction", parameter);  
...
return 0;


Sometimes, I get a segmentation fault.

As it turned out so far, the member variables in the second thread just have some random values, which indicates the there is some kind of pointer problem.

What did I do wrong and how can I do this properly?
Any advice is very appreciated! Thanks!

Re: Multithreading 1 year, 3 months ago #22015

Here's some example code for the stated problem.

I get the following output in naoqi:


secondFunction: stop = 153
secondFunction: x = -1092655373
secondFunction (after setting x to 'foo'): x = 151523040
secondFunction (after setting x to '2'): x = 2
firstFunction: x = 1
firstFunction: x = 1
firstFunction: x = 1
firstFunction: x = 1
...

Re: Multithreading 1 year, 3 months ago #22016

Sorry, the files were not accepted.
Attachments:
  • Page:
  • 1
Time to create page: 0.20 seconds