mne-cpp icon indicating copy to clipboard operation
mne-cpp copied to clipboard

[ENH, MAINT] MNE Scan: Separating plugins and threads.

Open gabrielbmotta opened this issue 3 years ago • 1 comments

Currently plugins <I>are</I> threads by virtue of the thread base class (All plugins inherit from either Sensor of Algorithm plugins, which in turn inherit from Abstract, which is, in main, subclassed from QThread). Currently this leads to a mental model of a plugins that is a single execution thread when 'start' is called. This is already not the case for the sensor plugins, which rely on 'Producer' objects that are on separate threads.

In an effort to limit our use of Qt to UI, this PR gets rid of the QThread subclassing and replaces it with uses of std::thread (to favor composition over inheritance: plugins have threads). ~~So far only the FiffSimulator plugin and Averaging plugins have been 'converted.'~~; I've only replaced the thread that previously existed by inheriting from QThread. I wanted to get a sense of what everyone thought of this, and what the new standardized way of doing threading should be.

In main, sensor plugins typically have a Producer class: which is also either a subclass of Thread or live in a separate Thread, The 'Producer' QThread could likewise be eliminated, either by likewise refactoring the class to use composition over inheritance and running it's <I>run()</I> in a separate thread, or the class could be eliminated completely by simply having that functionality be performed by a function in the main class, with the plugin having multiple threads as needed, with a function for each main loop, as necessary.

gabrielbmotta avatar Jan 24 '22 16:01 gabrielbmotta

Codecov Report

Merging #883 (2ad5e69) into main (bd31738) will increase coverage by 6.89%. The diff coverage is n/a.

:exclamation: Current head 2ad5e69 differs from pull request most recent head 9a47404. Consider uploading reports for the commit 9a47404 to get more accurate results

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #883      +/-   ##
==========================================
+ Coverage   30.20%   37.09%   +6.89%     
==========================================
  Files         452      195     -257     
  Lines       39208    11545   -27663     
==========================================
- Hits        11841     4283    -7558     
+ Misses      27367     7262   -20105     

see 281 files with indirect coverage changes

codecov[bot] avatar Jan 24 '22 17:01 codecov[bot]