Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我一直在试图弄清楚如何在 Raku 中进行文件锁定,但没有成功。我开始使用 NativeCall 研究 fcntl,但后来意识到 fcntl 锁不会阻止其他线程的文件访问。在 Raku 中进行文件锁定的最佳方法是什么?
IO::Handle 有一个lock和一个unlock方法来锁定/解锁文件。锁可以是独占的或共享的。
我遇到了这些 Raku 惯用短语并经常使用它们,为了简洁/清晰起见,“给定”主题化:
读:
given $path.IO.open { .lock: :shared; %data = from-json(.slurp); .close; }
写:
given $path.IO.open(:w) { .lock; .spurt: to-json(%data); .close; }