i am designing and developing an api where multiple threads are downloading files from the net and then write it to disk.

if it is used incorrectly it could happen that the same file is downloaded and written by more than one threads, which will lead to an exception at the moment of writing to disk.

i would like to avoid this problem with a `lock() { ... }` around the part that writes the file, but obviously i dont want to lock with a global object, just something that is related to that specific file so that not all threads are locked when a file is written.

i hope this question is understandable.