The three sample programmes in this directory show how you can launch a number of threads and
pass parameters to them.

------------------------------------------------
The first programme actually launches threads from within threads. There is some randomness
that is built into the children so that every time you run the programme, it will behave
a little differently and the order of printing will change each time.

Run by typing ./test_pthread

------------------------------------------------
The second programme is a test to show what happens when there are more threads running than
there are CPU cores. To see the number of CPU cores on the Pi, run the following command:

   cat /proc/cpuinfo


Each of the child threads is **not well written** in the sense that in order to cause a
software delay, they loop to waste CPU cycles. Normally you would not want to delay this way
when running under an operating system, because you will just prevent other programmes from
potentially using the CPU during the time you are wasting cycles. However for demo purposes,
this is a great way to cause the CPU load to exceed 100% of the available CPU cores.

If you run the second programme with one, two, three or four threads, the elapsed time will
more or less be the same on most 4-threaded Pis. However when you run five or more threads,
that is more than the number of CPU cores, and the execution time will slow down proportionally.
In fact, the operating system is doing other stuff at the same time, and will still do that.

If you run the second programme with a large number of threads, you will see it slows down
a lot, but even if the clock is running on the same Pi, the clock will appear to work OK!

Not the case though if you are playing media.... the media will not play cleanly when
the CPU is maxed out.

Run by typing ./test_pthread2 NNN (where NNN is the number of threads you wish to create)

Try running the second programme with (say) fifty threads (WAYYYYYYY more than the number
of CPU cores in a Raspberry Pi). If you have clock hardware connected, you will probably not
notice any change to the clock display even though the Raspberry Pi is so grossly overloaded,
you would think it would just fall over flat on its face.
------------------------------------------------

The third programme is similar to the second, but instead of wasting CPU cycles using delay
loops, the third programme does the 'correct' thing and calls the OS to implement its
delays. You will see that all threads will run in parallel as if the other threads were
not even there. The OS will not even blink with a very large number of threads running in
parallel and the programme will always finish in five seconds (because each thread delays
for five seconds total).

Run by typing ./test_pthread3 NNN (where NNN is the number of threads you wish to create)
