<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<oembed>
  <author_name>rubytips86</author_name>
  <author_url>https://blog.hatena.ne.jp/rubytips86/</author_url>
  <blog_title>Ruby Tips!</blog_title>
  <blog_url>https://rubytips86.hatenablog.com/</blog_url>
  <categories>
  </categories>
  <description>ファイルのロックには共有ロックと排他ロックがある。共有ロックは主に読み込み時に使用し、排他ロックは主に書き込み時に使用する。RubyでファイルをロックするにはFile#flockを使う。共有ロックを行うにはFile::LOCK_SHを、排他ロックを行うにはFile::LOCK_EXを指定する。 open('foo.txt'){|f| f.flock(File::LOCK_SH) # 共有ロック f.read } open('foo.txt'){|f| f.flock(File::LOCK_EX) # 排他ロック f.write &quot;hoge&quot; } ファイルのロックはファイルが閉じられると自動的に…</description>
  <height>190</height>
  <html>&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Frubytips86.hatenablog.com%2Fentry%2F2014%2F03%2F31%2F133921&quot; title=&quot;ファイルをロックする - Ruby Tips!&quot; class=&quot;embed-card embed-blogcard&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; style=&quot;display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;&quot;&gt;&lt;/iframe&gt;</html>
  <image_url></image_url>
  <provider_name>Hatena Blog</provider_name>
  <provider_url>https://hatena.blog</provider_url>
  <published>2014-03-31 13:39:21</published>
  <title>ファイルをロックする</title>
  <type>rich</type>
  <url>https://rubytips86.hatenablog.com/entry/2014/03/31/133921</url>
  <version>1.0</version>
  <width>100%</width>
</oembed>
