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

Avoid dynamic allocation for create_thread? #85

Closed
sunfishcode opened this issue Oct 18, 2023 · 0 comments · Fixed by #94
Closed

Avoid dynamic allocation for create_thread? #85

sunfishcode opened this issue Oct 18, 2023 · 0 comments · Fixed by #94
Labels
question Further information is requested

Comments

@sunfishcode
Copy link
Owner

Currently create_thread has a Box argument: fn_: Box<dyn FnOnce() -> Option<Box<dyn Any>>>.

This allows it to be passed a closure, and to be a safe function.

A possible alternative would be to do something more like pthread_create, and have it take a raw function pointer and a raw data pointer, which would mean it would be an unsafe function. One could argue that safety isn't the highest priority at this abstraction level, because Origin in general is a low-level API that most users wouldn't use directly anyway. Most users would use this through c-scape's pthread_create or Rust's std::thread API.

@sunfishcode sunfishcode added the question Further information is requested label Oct 18, 2023
sunfishcode added a commit that referenced this issue Nov 9, 2023
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 added a commit that referenced this issue Nov 9, 2023
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant