Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Execv unix calls fail with threaded program on Mac OS X. #4666

Closed
vicuna opened this issue Dec 6, 2008 · 5 comments
Closed

Execv unix calls fail with threaded program on Mac OS X. #4666

vicuna opened this issue Dec 6, 2008 · 5 comments
Assignees
Labels

Comments

@vicuna
Copy link

vicuna commented Dec 6, 2008

Original bug ID: 4666
Reporter: gguyomarch
Assigned to: @xavierleroy
Status: closed (set by @xavierleroy on 2009-01-26T17:15:28Z)
Resolution: fixed
Priority: normal
Severity: major
Version: 3.11.0+beta
Fixed in version: 3.11.1+dev
Category: ~DO NOT USE (was: OCaml general)
Related to: #4725
Monitored by: spivey hnrgrgr gguyomarch

Bug description

Prior to bug fix for #2867, threaded programs could overcome the following limitation of mac os x execve (execv failing with EOPNOTSUPP when a process as multiple active threads):

http://uninformed.org/index.cgi?v=1&a=1&p=16
http://lists.apple.com/archives/cocoa-dev/2005/Oct/msg00836.html

by forking first, see example below.

I do not know if there is a right thing to do though.

Thanks,
Gregory.

(* fork_exec.ml )
(
Compiled with:
ocamlbuild -tag use_unix -cflags "-I +vmthreads" -lflags "-I +vmthreads" -libs unix,threads fork_exec.byte
works on mac os x, but with the following, it will fails in execvp with EOPNOTSUPP in 3.11:
ocamlbuild -tag use_unix -cflags "-I +threads" -lflags "-I +threads" -libs unix,threads fork_exec.byte
Used to work in 3.10.2.
*)
let () =
let t = Thread.create (fun () -> ()) () in
Thread.join t;
Unix.handle_unix_error
(fun () ->
match Unix.fork () with
| 0 -> Unix.execvp "ls" [| "ls"; "-l" |];
| pid -> ()
) ();
;;

Gregoire Henri said:

#4577: reinitialize thread machinery after fork
#4577

The trick of systematically calling fork before exec in a threaded
program does not work anymore, because the ocaml Unix.fork restart a
thread after forking.

@vicuna
Copy link
Author

vicuna commented Dec 12, 2008

Comment author: @xavierleroy

That's a nasty bug in MacOS X. One possible fix would be to create the 'tick' thread on demand, i.e. the first time a thread is created after the initial launch of the program or after a fork (in the child process). I'll look into this.

@vicuna
Copy link
Author

vicuna commented Dec 14, 2008

Comment author: @xavierleroy

Tentative fix (on-demand creation of tick thread) in 3.11 release branch, to be included in 3.11.1 if it works.

@vicuna
Copy link
Author

vicuna commented Dec 19, 2008

Comment author: @xavierleroy

The same problem was reported under FreeBSD. The fix in the release branch appears to fix it.

@vicuna
Copy link
Author

vicuna commented Jan 24, 2009

Comment author: @damiendoligez

From: Mike Spivey

I wanted to add a note in Mantis (but couldn't see how to do it) to say
that I had encountered the problem described in #4666 in a program that
contains OCaml + LablGTK + GTK+OSX + threads + sockets. The fix that is
in the 3.11 release branch on CVS solved the problem for me.

Best wishes,

-- Mike Spivey

@vicuna
Copy link
Author

vicuna commented Jan 26, 2009

Comment author: @xavierleroy

Based on feedback so far, the fix appears to work. I'm closing this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants