]> Sergey Matveev's repositories - public-inbox.git/commitdiff
searchidxskeleton: add a note about locking
authorEric Wong (Contractor, The Linux Foundation) <e@80x24.org>
Sat, 3 Mar 2018 07:16:29 +0000 (07:16 +0000)
committerEric Wong (Contractor, The Linux Foundation) <e@80x24.org>
Sat, 3 Mar 2018 07:16:29 +0000 (07:16 +0000)
It's tempting to rely on the atomicity of smaller-than-PIPE_BUF
writes, but it doesn't work if mixed with larger ones.

lib/PublicInbox/SearchIdxSkeleton.pm

index 063c83e8db3091a6d26094995a794dbeb1ad75f2..506e566f8dba1ea1c9410d566cf80e257a601e5b 100644 (file)
@@ -80,6 +80,8 @@ sub index_skeleton {
        $str = length($str) . "\n" . $str;
 
        # multiple processes write to the same pipe, so use flock
+       # We can't avoid this lock for <=PIPE_BUF writes, either,
+       # because those atomic writes can break up >PIPE_BUF ones
        $self->_lock_acquire;
        print $w $str or $err = $!;
        $self->_lock_release;