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

Use a special metatable for thread userdata arguments #728

Closed
wants to merge 2 commits into from

Conversation

javalikescript
Copy link
Contributor

@javalikescript javalikescript commented Nov 3, 2024

This is a proposal for handling thread and async userdata arguments.

The current implementation copies the userdata block of raw memory, sets the same metatable then removes it after the callback.
This implementation requires the userdata usage to be thread-safe and not used after the callback.

As far as I see the main use case for passing userdata consists in passing async to the thread callback.
It is not possible to check if a userdata is thread-safe.
The userdata cannot be used after the callback which is fine for thread but not for async.

This change consists in letting the caller opt-in to pass the metatable by providing a dedicated metatable suffixed _ref.
Such metatable is provided for uv_async with no close nor gc.
There is still a major issue as the async could be garbage collected on the main side.

Another option would be to forbid all userdata arguments except async or not setting the metatable at all.

@javalikescript javalikescript marked this pull request as draft November 4, 2024 06:40
@javalikescript
Copy link
Contributor Author

Closed in favor of #729

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.

1 participant