Version française
Home     About     Download     Resources     Contact us    
Browse thread
Unix.lockf should support SEEK_SET flag
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Heejong Lee <ihji@r...>
Subject: Unix.lockf should support SEEK_SET flag
Hello, caml-list members

Let me suggest something very important to ocaml developers.

Recently, I'm developing an application that uses multi-cores. As we  
know, Ocaml doesn't have kernel level thread because of the garbage  
collector issues. Instead of real thread, I chose Cothread and Netshm  
for thread emulation using process and shared memory. Unfortunately, I  
suffered from a lot of strange bugs for many weeks.

After tracing every system call, I found the bug. Cothread and Netshm  
use record locking provided by Unix.lockf. On current implementation  
of Unix.lockf, locking method should be two steps, lseek and lockf.  
However, since forked processes share opened file offsets, race  
condition can happen between lseek and lockf. There were many bugs  
from the fact that both Netshm and Cothread use lseek and lockf. Their  
lockings would be incomplete in some situations.

To avoid this problem, I extended Unix.lockf to support SEEK_SET flag  
of fcntl to designate the offset directly. This solves all strange  
bugs above. I think that Unix.lockf should support SEEK_SET option  
officially.

I want to hear your opinions.

--
Heejong Lee