Skip to content

Fixing error when an instance of custom class is given to Thread#new#38

Merged
mattn merged 4 commits into
mattn:masterfrom
pbosetti:master
Apr 28, 2016
Merged

Fixing error when an instance of custom class is given to Thread#new#38
mattn merged 4 commits into
mattn:masterfrom
pbosetti:master

Conversation

@pbosetti
Copy link
Copy Markdown
Contributor

If you use the example/data.rb with the original source, you get a TypeError error on Thread#new call. This commit seems to solve it.

Related to this, I note here that the only working ways to exchange data among threads that I have found are:

  • to create a custom container class descending from Queue, and put what you want to exchange as an instance variable of Queue.
  • to use a mruby class that is MRB_TT_DATA in general (the same Queue is a MRB_TT_DATA)

So my question is: would it be dangerous/unadvisable to use the same vn = v assignment for all the data types in migrate_simple_value(), rather than make empty copies that start having different lives in different threads? I feel that having threads and not being able to share data among them is a large limitation, but perhaps there are some GC-related issues that rule out this possibility.

Any insight?

pbosetti added 4 commits April 2, 2015 14:31
…rived from Object

The original error says: "TypeError: wrong argument type NameError (expected Class)".
Added an example/data.rb to illustrate the problem. original code raising the exception is commented out.
@mattn mattn merged commit 41c7ea5 into mattn:master Apr 28, 2016
@mattn
Copy link
Copy Markdown
Owner

mattn commented Apr 28, 2016

Thanks. Btw, data.rb seems broken to me. shoud be count-up but not. (not depend on your change. this maybe my bug)

@pbosetti
Copy link
Copy Markdown
Contributor Author

pbosetti commented Apr 28, 2016

@mattn that is exactly the point: from what I understand, it is not counting up because the two threads are operating on different copies of the original object. If you replace lines 235 and 236 with:

nv = v;

then data.rb works as expected. But as I was saying in the PR, I am not sure it would not cause issues on the rest.
Moreover, the same holds for the other MRB_TT_* cases, except for MRB_TT_DATA, which is the only one that makes an alias (nv = v;) rather than an empty new copy.

I hope that my point (and my question) is clear.

@murasesyuka
Copy link
Copy Markdown
Contributor

Hi @pbosetti

add Makefile is need? this Makefile not run. because you remove run_test.rb.

$ make test
ruby ./run_test.rb test
ruby: No such file or directory -- ./run_test.rb (LoadError)
Makefile:3: recipe for target 'test' failed
make: *** [test] Error 1

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.

3 participants