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

Enable reserved_stack argument to Threads.@spawn #55201

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

MilesCranmer
Copy link
Member

@MilesCranmer MilesCranmer commented Jul 21, 2024

Fixes #55200. The mechanism is to simply forward whatever is passed to a reserved_stack keyword to the reserved_stack argument in Task. By default this is 0, so that is also the macro default.

Usage:

Threads.@spawn reserved_stack=(8 * 1024 * 1024) sleep(100)
# => Task(() -> sleep(100), 8 * 1024 * 1024)

It is compatible with the threadpool argument, and the order is arbitrary:

stack_size = 4 * 1024^2
Threads.@spawn :interactive reserved_stack=stack_size sleep(100)
Threads.@spawn reserved_stack=stack_size :interactive sleep(100)

x-ref #55200 #55185 #55184 #54998

@ararslan ararslan added needs news A NEWS entry is required for this change needs compat annotation Add !!! compat "Julia x.y" to the docstring labels Jul 26, 2024
@MilesCranmer
Copy link
Member Author

@ararslan both have been added

@ararslan ararslan added multithreading Base.Threads and related functionality and removed needs news A NEWS entry is required for this change needs compat annotation Add !!! compat "Julia x.y" to the docstring labels Aug 13, 2024
Copy link
Member

@vchuravy vchuravy left a comment

Choose a reason for hiding this comment

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

I am not a fan of mixing both keyword argument and positional style in macros.
It makes them quite a bit harder to read. I would make the order required with threadpool; kwargs... like a normal function call.

I wonder if we could factor out the logic of parsing the kwargs to the macro.
It looks similar to gen_call_with_extracted_types_and_kwargs

@MilesCranmer
Copy link
Member Author

I wonder if we could factor out the logic of parsing the kwargs to the macro. It looks similar to gen_call_with_extracted_types_and_kwargs

I was meaning to ask about this. Is there was a standard way to handle kwargs in Julia macros that live in Base?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
multithreading Base.Threads and related functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make stack size configurable in Threads.@spawn
3 participants