Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0007264OCamlplatform support (windows, cross-compilation, etc)public2016-05-23 16:212017-02-16 09:39
Reporterdra 
Assigned To 
PrioritynormalSeveritymajorReproducibilityalways
StatusresolvedResolutionfixed 
PlatformOSOS Version
Product Version4.02.2 
Target Version4.05.0 +dev/beta1/beta2/beta3/rc1Fixed in Version4.05.0 +dev/beta1/beta2/beta3/rc1 
Summary0007264: Unix.lockf doesn't behave correctly on Windows
DescriptionUnix.lockf on Windows seems to lock out file handles on the same file for the current process as well.
Steps To ReproduceIn a toploop with unix.cma loaded:

# let fd = Unix.(openfile "foo" [O_CREAT; O_RDWR] 0o666);;
val fd : Unix.file_descr = <abstr>
# Unix.(lockf fd F_LOCK 0);;
- : unit = ()
# Unix.(write_substring fd "foo" 0 3);;
- : int = 3
# let fd2 = Unix.(openfile "foo" [O_CREAT; O_RDWR] 0o666);;
val fd2 : Unix.file_descr = <abstr>
# Unix.(write_substring fd2 "foo" 0 3);;
Exception: Unix.Unix_error (Unix.EACCES, "write", "").
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0015951)
dra (developer)
2016-05-25 11:43

I've done a bit more investigation here and found two more things:
1. Lock promotion doesn't work - i.e. Unix.(lockf fd F_RLOCK 0; lockf fd F_LOCK 0) will block
2. Blocking out other file handles within the same thread/process is the intended behaviour of the LockFile Windows API call

I can see how the Unix module could work around problem 1 (it's just yet another instance of needing to add information to the fd structure!), but I can't see an easy way to work around the other problem without having to track all open file descriptors and re-map them.
(0016713)
xleroy (administrator)
2016-12-07 14:49

Clearly, POSIX and Win32 give different semantics to file locks. I think it is hopeless to commit on one semantics and emulate it on the other OS (or one both): this sounds technically very difficult, and moreover it's not obvious to me which semantics is the right one! My proposal is just to document the differences in behavior.
(0017268)
xleroy (administrator)
2017-02-16 09:39

Updated the documentation of Unix.lockf to mention this difference between Win32 and POSIX.

- Issue History
Date Modified Username Field Change
2016-05-23 16:21 dra New Issue
2016-05-25 11:43 dra Note Added: 0015951
2016-06-21 12:52 frisch Category OCaml otherlibs => OCaml windows
2016-09-27 14:02 doligez Target Version => 4.05.0 +dev/beta1/beta2/beta3/rc1
2016-09-27 14:02 doligez Status new => acknowledged
2016-12-07 14:49 xleroy Note Added: 0016713
2017-02-16 09:39 xleroy Note Added: 0017268
2017-02-16 09:39 xleroy Status acknowledged => resolved
2017-02-16 09:39 xleroy Resolution open => fixed
2017-02-16 09:39 xleroy Fixed in Version => 4.05.0 +dev/beta1/beta2/beta3/rc1
2017-02-23 16:46 doligez Category OCaml windows => platform support (windows, etc)
2017-02-23 17:16 doligez Category platform support (windows, etc) => platform support (windows, cross-compilation, etc)


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker