Added a lock to prevent simultaneous dumps from multiple threads.

Function save_dump now returns the file name and the headers.
If the file name comtains the sub-string '{sequence_number}', it is replaced by the running number of the dump.