スレッド概要
YARV のスレッドモデルの概略をつかむのには、yarv-dev や ruby-dev のささださんの投稿を参考にしました。
今のところは、model 2、つまり「一つのRubyスレッドが一つのネイティブスレッドに対応する」けれども「ある時点で稼働状態にあるスレッドは一つだけ(VM全体で1個のMutexを共有していて、そのMutexを取ったスレッドしか稼働しない)」となっているようです。
スレッド実装のソースファイルは
- thread.c
- thread_pthread.h
- thread_pthread.ci
- thread_win32.h
- thread_win32.ci
です。.ciファイルはthread.cの中に#includeで使うファイル。pthread/win32 はそれぞれの環境のスレッド機能をラップしたもので、
- Init_native_thread
- native_thread_create
- native_thread_destroy
- native_thread_apply_priority
- native_thread_yield
- native_thread_join
- native_sleep
- native_mutex_initialize
- native_mutex_destroy
- native_mutex_trylock
- native_mutex_unlock
- native_mutex_lock
という関数が用意されています。それぞれ名が体を表しているので詳細は省略。