mattn / mattn/mruby-thread

Behavior of Thread::new() on passed instances

Open
#39 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
49
Forks
31
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the original implementation referenced in #38 and the experimental branch pbosetti/mruby-thread. Compare the two MRB_THREAD_COPY_VALUES behaviors using examples/data.rb, then determine whether shared instances are an accepted design and what tests or documentation would define the intended Thread::new behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
operating-systems
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.