flexivrobotics / flexiv_rdk

RDK (robotic development kit) for Flexiv robots. Supports C++ and Python. Compatible with Linux, macOS, and Windows.
Apache License 2.0
58 stars 18 forks source link

Does flexiv::Scheduler::stop return instantly? #33

Closed acf986 closed 10 months ago

acf986 commented 10 months ago

@pzhu-flexiv Given the following situation:

  1. flexiv::Scheduler::start function is called in the main thread to start a worker thread without blocking the main thread.
  2. Later in the main thread, flexiv::Scheduler::stop is called to stop the worker thread.

My question is:

  1. Will flexiv::Scheduler::stop return instantly, or it will wait for the worker thread to finish completely (sth like thread.join)?
  2. Similarly, if the flexiv::Scheduler::start is called without blocking, does it return immediately? or it guarantees the scheduled task thread is already running when the start() function returns?
pzhu-flexiv commented 10 months ago

@acf986

  1. Scheduler::stop only sends a stop signal to the running tasks and returns immediately, so no blocking here. The "thread.join" functionality is taken care of by Scheduler::start(true)
  2. Scheuler::start(false) blocks for a very short period of time to make sure the tasks have already started before returning. So yes, start(false) guarantees the tasks are already running before it returns.