Skip to content

Add NoThreadClone#isShareable method so the elements can dynamically decide if they need cloning or not#5916

Draft
vlsi wants to merge 1 commit intoapache:masterfrom
vlsi:isshareable
Draft

Add NoThreadClone#isShareable method so the elements can dynamically decide if they need cloning or not#5916
vlsi wants to merge 1 commit intoapache:masterfrom
vlsi:isshareable

Conversation

@vlsi
Copy link
Copy Markdown
Collaborator

@vlsi vlsi commented May 12, 2023

Motivation and Context

Previously, components could implements NoThreadClone to prevent cloning in each thread, however, there was no way to "unimplement" the interface.

By default, isShareable returns true, so existing components work as before.

This improvement is needed for:

…decide if they need cloning or not

Previously, components could implements NoThreadClone to prevent cloning in each thread,
however, there was no way to "unimplement" the interface.

By default, isShareable returns true, so existing components work as before.
@vlsi
Copy link
Copy Markdown
Collaborator Author

vlsi commented May 13, 2023

It looks like another API is needed so the component can figure out if the actual element has been cloned or not.

For instance, in case like #727, HeaderManager#assertMutable() should be able to tell if the specific HeaderManager is cloned or not.
If a code creates a temporary HeaderManager object for the purpose of merging the headers, then the temporary HeaderManager should not fail with something like "oh, this is a shared instance, stop modifying it".

It sounds like NoThreadClone#freeze() method which would signal the component the instance is reused.

Then TreeCloner would call freeze on non-cloned objects.


Unfortunately, it reminds me of the new memory management in Kotlin Native : https://kotlinlang.org/docs/native-migration-guide.html
Initially, they had a memory model which the user must call freeze object before sharing the object cross-threads.
That memory model has proven to be hard to use, and they went with a garbage collector.
Even though our goals are slightly different, it sounds related.

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