Simplify list_clear(), allow NULL as free() function pointer.

This makes it redundant to create a null_free() or dummy_free() function
that does nothing.
Added a notification mechanism for sending messages from
another thread to the mainthread in a safe manner.

This is used for the DNS lookup code, and can also
be used by the signal handler to safely report actions back
to the application mainloop without using global variables.