<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<p><br>
/mnt/d/dev2/cm3-5.8.6/m3-libs/libm3/src/os/POSIX/ProcessPosixCommon.m3</p>
<p><br>
</p>
<p>PROCEDURE Create_ForkExec:</p>
<p>.<br>
.<br>
.<br>
(* Turn off the interval timer (so it won't be running in child). *)</p>
<p> nit := Utime.struct_itimerval { <br>
it_interval := Utime.struct_timeval {0, 0}, <br>
it_value := Utime.struct_timeval {0, 0}}; <br>
IF Utime.setitimer(Utime.ITIMER_VIRTUAL, nit, oit) < 0 THEN <br>
<* ASSERT FALSE *> <br>
END; <br>
. <br>
. </p>
<p> .</p>
<p> fork() </p>
<p> . <br>
. </p>
<p><br>
(* Enable scheduler. *) <br>
Scheduler.EnableSwitching (); </p>
<p> (* Restore previous virtual timer. *) <br>
IF Utime.setitimer(Utime.ITIMER_VIRTUAL, oit, nit) < 0 THEN <br>
<* ASSERT FALSE *> <br>
END; </p>
<p> <br>
This code has a number of problems. </p>
<p> - It looks thread-unsafe -- another thread could be changing the timer. </p>
<p> </p>
<p> - The comments are wrong in multiple ways.<br>
The timer doesn't have to be turned off to not run in the child.<br>
Timers except alarm() are not inherited by child.<br>
It goes ahead and enables in the child anyway. Granted, after EnableSwitching,<br>
which also enables it! </p>
<p><br>
</p>
<p> - Doesn't work on Microsoft's Windows Subsystem for Linux (WSL).</p>
<p> You get back -1/EINVAL.</p>
<p><br>
</p>
<p> - Is probably specific to user threads?</p>
<p> </p>
<p>- Fails to put a useful message in the assert other than "FALSE"</p>
<p> </p>
<p>Proposals:</p>
<p> 1. Remove it.<br>
2. Make it check for and ignore EINVAL, and possibly WSL, and not then enable in child.<br>
3. Change it to get in parent and set in child if enabled. </p>
<p> 4. Move it to Thread.AtFork in user threads. Though again, not clearly needed there.</p>
<p><br>
</p>
<p> 5. Consider that fork+exec should work from C/C++ code in a process that is using Modula3.</p>
<p><br>
</p>
<p> 6. Research posix_spawn and use it more. </p>
<p> We can probably just use it and forget about any system that lacks it.</p>
<p><br>
Thoughts?</p>
<p> WSL can be detected by searching for "Microsoft" in /proc/sys/kernel/osrelease or /proc/version.</p>
<p><br>
</p>
<p> Or we can just accept -1/EINVAL here for any OS.</p>
<p><br>
</p>
<p><br>
</p>
<p> - Jay</p>
<p><br>
</p>
</div>
</body>
</html>