Project

General

Profile

Actions

Bug #712

closed

Fix thread management in all apps

Added by Hammel over 5 years ago. Updated about 5 years ago.

Status:
Closed
Priority:
Immediate
Assignee:
Category:
04 - Applications
Target version:
Start date:
26 Jun 2019
Due date:
% Done:

100%

Estimated time:
Severity:
01 - Critical

Description

I have lousy thread management in my apps. The current design for all apps is this.

  1. Start all threads
  2. each thread spins looking for work
    1. if no work, short delay and spin again
  3. spin in main thread till exit

This has worked fine up till now but it sucks. The threads are polling for work and spinning wildly if there isn't any. There are artificial delay loops to slow them down, but it's sucking the life out of the Pis, especially the Pi Zero. I disable some of the threads on Xeon builds but that's a hack. I need better thread synchronization.

What should really happen is this.
  1. Start event queue thread waiting on network or other I/O via select() or similar.
  2. Inbound message placed on appropriate queue.
  3. start thread for that queue is called.
In the other thread.
  1. If started, return (prevents multiple thread starts)
  2. Run the queue until exhausted.
  3. Exit the thread.

The start-thread call uses a mutex on a variable that can tell when the thread has exited.

There should never be more than one thread started when the app starts and that thread should be waiting on kernel events (network or other I/O) so that it's not polling and chewing up CPU time.

In other words: apps should be idle unless there is actual work to do!

Apps to review and fix:
  1. piboxd
  2. appmgr
  3. videofe
  4. musicfe
  5. jarvis
  6. picam
  7. pidialer
  8. pipics
  9. pixm

Note: Everything that uses the piboxTouchProcessor() should be reviewed but mostly the piboxTouchProcessor() should be checked to make sure it's event driven and not polling. I don't think msgProcessor.c or queueProcessor.c in libpibox are being used yet but they should be checked too.


Related issues

Blocked by VideoFE - Bug #714: omxplayer FIFO control is brokenClosedHammel15 Sep 2019

Actions
Blocked by piboxd - Bug #721: Missing resolv.conf causes MT_NET SET_IPV4 to hangClosedHammel20 Oct 2019

Actions
Actions

Also available in: Atom PDF