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

Make Process#wait asynchronous on Windows #13908

Merged

Conversation

HertzDevil
Copy link
Contributor

Fixes #13492.

Every Crystal::System::Process now carries a Win32 job object that holds the process handle (but not its child processes). The job object then indicates process termination via an IOCP message, which Crystal's event loop already employs. Note that those messages have their own format and do not have a real LibC::OVERLAPPED.

This also effectively makes the playground work on Windows.

Does not affect #13425.

src/crystal/system/win32/process.cr Outdated Show resolved Hide resolved

# at the moment only `::Process#wait` uses a non-nil completion key; all
# I/O operations, including socket ones, do not set this field
case completion_key = Pointer(Void).new(entry.lpCompletionKey).as(CompletionKey?)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose it's probably okay to leverage the fact that unions of a reference type and Nil are represented as a simple pointer where the null pointe rexpresses a nil value. But it feels just a tiny bit iffy.
Feel free to ignore this comment, or refactor for a more explicit null pointer check if you think it makes sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this is the same assumption in Atomic and Box. Perhaps these special casts can be placed under something like Crystal::ABI later

@straight-shoota straight-shoota added this to the 1.11.0 milestone Oct 27, 2023
@straight-shoota straight-shoota merged commit 26819e3 into crystal-lang:master Oct 28, 2023
53 of 55 checks passed
@HertzDevil HertzDevil deleted the bug/windows-process-run-async branch October 28, 2023 11:00
Blacksmoke16 pushed a commit to Blacksmoke16/crystal that referenced this pull request Dec 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

WebSocket in child process gets stuck on Windows
2 participants