APCUPSD now is using threads (processes) and IPC shared memory for
all its operations. On blocking operations, we make use of timed select()
to ensure short thread execution. There is one chunk of shared memory that
is an UPSINFO structure and this is the way all threads communicate one
to the other. The area must be locked before modifying it and can be unlocked
only at the end of an handler. The area can be leaved unlocked only if
the routine involved don't want to modify myUPS.
Graph of operations:
+- net thread ---+
|
\
apcupsd ------+- serial thread -[ UPSINFO shared structure]
|
/
+- client thread -+
If a thread must write to shared structure we _have_ to lock it. Imagine
serial and net that need to write:
We have to lock the data until the thread is ended:
This is called serialization. For read-only threads we just wait
for unlock then read shared data and unlock and that's all.