Git Product home page Git Product logo

Comments (10)

MaximilienNaveau avatar MaximilienNaveau commented on May 23, 2024

I suggest we use boost for this:

#include <boost/thread/thread.hpp>
#include <boost/asio/io_service.hpp>

This allows you to spawn a pool of thread and then send them a pointer to a function to execute using boost::bind.
It's very efficient.

from motion_capture_system.

versatran01 avatar versatran01 commented on May 23, 2024

Does this approach require joining the thread at each frame?

I had a quick glance at the codebase and I found some questionable design choices that I don't quite understand.
Specifically, why does the subject class need a mutex and why is it stored as a shared_ptr in a map.
Why disable copy for Subject and KalmanFilter? They should have value semantics.
And even the driver base class has an unnecessary mutex.

from motion_capture_system.

versatran01 avatar versatran01 commented on May 23, 2024

I think the reason why everything is a shared_ptr is because there is a mutex in the Subject class. Again I fail to understand why this is needed. The only way a mutex is necessary is when functions like

    string subject_name =
      client->GetSubjectName(i).SubjectName;

will return duplicate subject_name, but that shouldn't be the case.

from motion_capture_system.

MaximilienNaveau avatar MaximilienNaveau commented on May 23, 2024

Does this approach require joining the thread at each frame?

Not that I know of, this is why I suggested it.
I believe boot creates a pool of thread always active and you send them by a safe way a pointer to a method to execute.
You can still wait until the method is done but it's not joining the thread, the thread goes idle until another method is sent to it.

from motion_capture_system.

versatran01 avatar versatran01 commented on May 23, 2024

I'm not an expert in asio, but my understanding is one can just call io_service::post to give some work to the ios_service's internal thread pool? Is that what you are proposing here?

Also I'd love to get rid of all these random mutexes if possible.

My personal preference would be TBB of course, but using asio is also ok since we already depend on boost.

from motion_capture_system.

MaximilienNaveau avatar MaximilienNaveau commented on May 23, 2024

I'm not an expert in asio, but my understanding is one can just call io_service::post to give some work to the ios_service's internal thread pool? Is that what you are proposing here?

Yes, I suggest to do this:

// thread pool :
boost::asio::io_service io_service;
boost::asio::io_service::work io_work(io_service);
boost::thread_group threadpool ;
// add one thread (or more) to the thread pool
threadpool_.create_thread(boost::bind(&boost::asio::io_service::run, &io_service_));

// Make the thread work using post
io_service_.post(boost::bind(&my_method, a_class_object, some_arg1, some_arg2));

// end of program (in the destructor of a class for example)
io_service.stop();
threadpool.join_all();

I personally prefer boost as it's:

  • a very standard dependency,
  • cross platform
  • usually already installed when using ROS1/2
  • easy to use using CMake

from motion_capture_system.

versatran01 avatar versatran01 commented on May 23, 2024

Cool, this looks good. If you can do another PR, I'd be happy to review and merge it.
I think for this particular one just change the vector of threads to asio and thread_pool.
It would also be nice to get a rough performance measure before and after.
We will worry about mutexes later.

from motion_capture_system.

MaximilienNaveau avatar MaximilienNaveau commented on May 23, 2024

I won't have time to do this before end of June but I will try later on.

from motion_capture_system.

MaximilienNaveau avatar MaximilienNaveau commented on May 23, 2024

If I do this I could also update the mutex problem.

from motion_capture_system.

versatran01 avatar versatran01 commented on May 23, 2024

There's no hurry, I'm not sure how many people in our lab are using this atm.

My quick scan through the code shows that there's one mutex per Subject, which makes it non-copyable. If we remove it we can just use Subject instead of SubjectPtr.
There's also one in each driver class, which is also not doing anything useful. I'd say it's safe to remove both with very limited refactoring.

from motion_capture_system.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.