如何在Windows上独占锁定文件?

huangapple go评论85阅读模式
英文:

How do I exclusively lock a file on Windows?

问题

我想在Windows环境下独占锁定文件,但是syscall.Flock在Windows上不受支持。有没有办法实现它?

我尝试了这篇文章的方法,但是它不起作用(syscall.Syscall6引发了"Access is denied."错误)。

英文:

I want to lock file exclusively on Windows environment, but syscall.Flock isn't supported by Windows.
Is there any way to implement it?

I tried <a href="http://ikarishinjieva.github.io/tachikoma-blog/post/2014-03-20-go-file-lock/">this article</a>'s method however it doesn't work (syscall.Syscall6 raises "Access is denied." error).

答案1

得分: 1

Windows的C++ API可以帮助你。LockFileLockFileEx函数似乎足够帮助你。

英文:

Windows c++ api could help you. The LockFile and LockFileEx functions seem enough to help.

huangapple
  • 本文由 发表于 2015年8月8日 21:52:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/31893803.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定