How lock keyword in open function in julia is used?

Viewed 85

The open(filename::AbstractString; lock = true, keywords...) function has a keyword lock. According to official documentation "The lock keyword argument controls whether operations will be locked for safe multi-threaded access." Even after putting lock keyword to true explicitly, I can open the same file in different a process(for testing I used 2 julia REPLs) and edit it from both process. Now, my questions are:

  1. What does lock keyword actually do?
  2. Is there any way to open a file exclusively in a process and make other processes wait for it to prevent data race?
  3. Even after lock=true, can the file get corrupted if two processes try to write it at the same time?
  4. What does "safe multi-threaded access" mean in this context?

I am using Julia 1.7.3 on linuxmint 20.3

0 Answers
Related