Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>They're totally different.</p> <p>Locking means you use some method to control file access using locks. This stops two processes writing to the same file at the same time, stops one writing while another is reading, but allows two to read at the same time.</p> <p>Blocking means the method will wait for the operation to complete before returning.</p> <p><strong>Update</strong></p> <p>In response to the request for examples... I will try to add examples if I get time, but for now, here's an explanation of the possibilities.</p> <p>We have 3 ways to perform locking:</p> <ul> <li>None</li> <li>Blocking. If the lock is unavailable, wait for it.</li> <li>Non-blocking. If the lock is unavailable, fail.</li> </ul> <p>And 2 ways to perform IO:</p> <ul> <li>Blocking. Wait until the buffers are ready.</li> <li>Non-blocking. Fail if we can't read/write immediately</li> </ul> <p>If we use <code>open()</code> and <code>read()</code> as normal, we get blocking IO. If we want non-blocking IO we have to pass the <code>O_NONBLOCK</code> flag to <code>open()</code>, and <code>read()</code> will then return <code>E_AGAIN</code> instead of blocking.</p> <p>By default there is no locking. We can call <code>fcntl()</code> with <code>F_SETLK</code> or <code>F_SETLKW</code> to obtain the lock. The former blocks if the lock is unavailable, the latter fails with <code>EACCES</code> or <code>EAGAIN</code>.</p> <p>I think there are two possible points of confusion:</p> <ul> <li>IO can be blocking/non-blocking, locking can be blocking/non-blocking.</li> <li>Aside from data not being ready, a IO request can block because another process has the file locked.</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload