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

Behavior of Thread::new() on passed instances #39

Open
pbosetti opened this issue Apr 29, 2016 · 4 comments
Open

Behavior of Thread::new() on passed instances #39

pbosetti opened this issue Apr 29, 2016 · 4 comments

Comments

@pbosetti
Copy link
Contributor

The original implementation (see also #38) is designed so that Thread.new(a) makes a full copy of a in the newly created thread (unless mrb_type(a) == MRB_TT_DATA).
As a consequence, changes to a in any given thread are not visible to the other threads. This way, passing information between threads becomes a hard task.

Since I am still not sure about the reasons behind this choice, I have made an experimental branch in my own fork (pbosetti/mruby-thread) where the C macro MRB_THREAD_COPY_VALUES can be set to enable the original behavior (make copies) or leave undefined to switch to a "share the same instances" behavior.

The script examples/data.rb can be used to compare the two cases: when MRB_THREAD_COPY_VALUES is set, the changes to globals $data and $ary made in the subthread are not visible into the main thread. Conversely, if MRB_THREAD_COPY_VALUES, any change to instances passed to Thread::new() are visible to other threads.

The question is: can I make a PR for this?

Thanks,
Paolo

@pbosetti
Copy link
Contributor Author

pbosetti commented May 6, 2016

Hello @mattn any update on this?

@mattn
Copy link
Owner

mattn commented May 6, 2016

Sorry, I'll look into it in later.

@pbosetti
Copy link
Contributor Author

pbosetti commented May 6, 2016

@mattn no problem, didn't want to put pressure, just wanted to be suer you got the notification. More than often it happened to me 😉

@mattn
Copy link
Owner

mattn commented May 8, 2016

The question is: can I make a PR for this?

Yes, please do it. I hope that mruby-thread can handle instances created by another thread.

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

No branches or pull requests

2 participants