26.02.2014 Views

Getting Started with QNX Neutrino - QNX Software Systems

Getting Started with QNX Neutrino - QNX Software Systems

Getting Started with QNX Neutrino - QNX Software Systems

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

More on synchronization<br />

© 2009, <strong>QNX</strong> <strong>Software</strong> <strong>Systems</strong> GmbH & Co. KG.<br />

State<br />

CONDVAR<br />

MUTEX<br />

READY<br />

INTERRUPT<br />

Meaning<br />

Waiting for the underlying condition variable associated <strong>with</strong> the<br />

sleepon<br />

Waiting for a mutex<br />

Capable of using, or already using, the CPU<br />

Waiting for an interrupt from the hardware<br />

Action Mutex owner Consumer state Producer state<br />

Consumer locks mutex Consumer READY INTERRUPT<br />

Consumer examines data_ready Consumer READY INTERRUPT<br />

Consumer calls pthread_sleepon_wait() Consumer READY INTERRUPT<br />

pthread_sleepon_wait() unlocks mutex Free READY INTERRUPT<br />

pthread_sleepon_wait() blocks Free CONDVAR INTERRUPT<br />

Time passes Free CONDVAR INTERRUPT<br />

Hardware generates data Free CONDVAR READY<br />

Producer locks mutex Producer CONDVAR READY<br />

Producer sets data_ready Producer CONDVAR READY<br />

Producer calls pthread_sleepon_signal() Producer CONDVAR READY<br />

Consumer wakes up, pthread_sleepon_wait() tries<br />

to lock mutex<br />

Producer MUTEX READY<br />

Producer releases mutex Free MUTEX READY<br />

Consumer gets mutex Consumer READY READY<br />

Consumer processes data Consumer READY READY<br />

Producer waits for more data Consumer READY INTERRUPT<br />

Time passes (consumer processing) Consumer READY INTERRUPT<br />

Consumer finishes processing, unlocks mutex Free READY INTERRUPT<br />

Consumer loops back to top, locks mutex Consumer READY INTERRUPT<br />

The last entry in the table is a repeat of the first entry — we’ve gone around one<br />

complete cycle.<br />

What’s the purpose of the data_ready variable? It actually serves two purposes:<br />

62 Chapter 1 • Processes and Threads April 30, 2009

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!