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

Redesign create_thread to avoid dynamic allocation. #94

Merged
merged 1 commit into from
Nov 9, 2023

Conversation

sunfishcode
Copy link
Owner

Change create_thread from taking a boxed closure to taking a function pointer, as well as an array of pointers to be copied into the new thread to pass to the function. This avoids the need to dynamically allocate for a Box, and in particular it allows c-ward's pthread_create to be used from within malloc implementations.

And, implement thread return values, which is simpler with the removal of Option<Box<dyn Any>>.

These changes do create more work for users of the API, however it also gives them more control.

Fixes #85.

Change `create_thread` from taking a boxed closure to taking a function
pointer, as well as an array of pointers to be copied into the new thread
to pass to the function. This avoids the need to dynamically allocate for
a `Box`, and in particular it allows c-ward's `pthread_create` to be used
from within `malloc` implementations.

And, implement thread return values, which is simpler with the removal of
`Option<Box<dyn Any>>`.

These changes do create more work for users of the API, however it also
gives them more control.

Fixes #85.
@sunfishcode sunfishcode merged commit 71a37ab into main Nov 9, 2023
5 checks passed
@sunfishcode sunfishcode deleted the sunfishcode/thread-nobox branch November 9, 2023 21:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Avoid dynamic allocation for create_thread?
1 participant