-
-
Notifications
You must be signed in to change notification settings - Fork 706
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
Issue 20257 - Add wait(Pid, Duration) for windows #7528
Conversation
|
Thanks for your pull request and interest in making D better, @MoonlightSentinel! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla references
Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + phobos#7528" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good addition though unsure about more platform-specific functionality to Phobos. Would be good to ensure that it's possible to implement such things on top of Phobos functionality (i.e. using Pid.osHandle).
142452f to
7977416
Compare
Agreed, implementations for other platforms should be added in the future.
You mean a generic implementation for other platforms that doesn't depend on os-specific functions? |
Not necessarily. I recall that there was some friction with doing some things which are partially doable with |
|
There's not a portable option for Linux AFAIK. You need to use signals with another thread which can send the signal. I don't know if this is something we would want to implement in Phobos. I doubt there are going to be any advancements in Linux/Unix that allow for a wait with a timeout. So if we add this, it will likely be permanently Windows-only. And I think that's fine, we should expose the OS functionality available for the OS you are using. For example, we have config options which are OS specific (though those are just ignored on other OSes). |
|
Hm... I take it back (a bit), SIGALRM can be used without threads to implement this. So perhaps it is possible. But the granularity is possibly in seconds, which is not ideal. |
Internet says BTW, this task is achievable in a cross-platform manner without any changes in Phobos by creating a pipe and passing one end to the process, and then using |
|
It highly depends on the child process. The process could close the pipe without exiting because it doesn't plan to do any output. So I don't think it's portable for all situations. Edit: oh you mean a special pipe for this purpose. Hm... it's possible. You could fork/exec and set the noinherit on the pipe before the exec. Edit 2: Nevermind, I was thinking of FD_CLOEXEC, which doesn't help. |
Yeah, the more I look at it, the less nice it looks. |
It doesn't have to be |
|
Could also consider |
|
How about a control loop with auto waitTimeOut(Pid p, Duration timeout)
{
Duration ellapsted;
ReturnType!trywait result;
while (ellapsted < timeout)
{
result = tryWait(p);
if (result.terminated)
return r;
Thread.sleep(10.msecs);
ellapsted += 10.msecs;
}
return result;
}that would work for linux as well |
|
Busy waiting is inefficient because the parent keeps consuming resources and also imprecise because you wait way too long depending on your sleep duration. I could kinda see it as an "if all else fails" solution but i don't think it's appropriate for phobos. |
|
sigtimedwait probably isn't usable, that example doesn't seem to account for the possibility of waiting for a specific child, or in a thread. |
|
I think the idea is that after every SIGCHLD, you check (as in |
|
I would expect the SIGCHLD to immediately re-fire if you don't wait for the child that caused the signal. Is that not true? |
|
Sorry, I don't know. You may be right. |
a90d3d3 to
c49fc4d
Compare
c49fc4d to
25dfbb6
Compare
|
Anybody got an idea how to fix LDC-Win32 on Azure? |
4e3ae4f to
d3f0c6c
Compare
|
@MoonlightSentinel Maybe it was a spurious failure? Maybe you can rebase this and see what the autotester has to say? |
|
Don't think so, the failure persistet across several runs. I'll try a modified test case. |
d3f0c6c to
cf7bfc6
Compare
cf7bfc6 to
fef5faa
Compare
`wait(Pid, Duration)` allows to wait until the process terminates or the timeout expires. It's currently windows-only because a decent posix implementation is quite difficult and this allows us to sort out the API beforehand.
3b0f9a1 to
0317d1d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
wait(Pid, Duration)allows to wait until the process terminatesor the timeout expires.
It's currently windows-only because a decent posix implementation
is quite difficult and this allows us to sort out the API beforehand.
CC @andralex as this introduces a new symbol