Skip to content

Architecture: Threading

localghost edited this page Jun 27, 2014 · 45 revisions

Tasks

Information related to tasks can be found here.

Global threads

There will probably be a couple of threads that would be accessed by different classes, e.g. thread through which all the libspotify API calls should be made.

List of global threads:

  • spotify_thread : all the libspotify API calls should be done through this thread

Things to reconsider

Queue a task to a not running thread?

Possible solutions for adding tasks to a not running thread:

  • Add a task so that it is executed whenever the thread is started
  • Change the function's signature to return bool(false) and do not add task to the queue
  • Assert when thread is not running (current approach)
  • Throw exception if thread is not running

Start/stop thread

Currently, a thread can be stopped and re-started. However, the restart causes a new platform thread (std::thread) to be created. This is a common approach AFAIK but if there are tasks left not executed before the thread is stopped then on a restart they will be run but on a different thread! Reconsider whether this is a valid approach - client developer might expect that if she put tasks on a specific thread then that's where they are gonna be executed.

Suggested solutions:

  • clear the message loop on stop or before re-starting (add appropriate API in base::message_loop)
  • ...
Clone this wiki locally