I am constructing a program that does several things.
- Listens to a port. Every second a string is received
- When new data is received, it has to be logged. No errors or skipped entries are allowed
- When data is received, a plot on the screen has to be updated. This is an expensive computation. Missing some updates is not critical.
- Once a month, an archiving function shall be called, to backup the logs. This might take unknown amount of time.
I am new to threading and would like to ask for advice on the threading infrastructure. On one hand, it seems that I need at least 1 additional thread besides the main thread, for the port listener.
On the other hand, I am afraid that if I spawn too many a thread:
- Sync problems may occur
- The app may become resource-hungry
Here is some proposed code for the listener. * The complexity of the code might rocket up