Project

General

Profile

Actions

Bug #4770

closed

[Q] thread->interrupt_flag が適切に排他制御されていないように見える

Added by kosaki (Motohiro KOSAKI) almost 13 years ago. Updated almost 13 years ago.

Status:
Closed
Target version:
ruby -v:
-
Backport:
[ruby-dev:43467]

Description

kosakiです

Ruby VM internal
に詳しい方々に質問です。現在、thread->interrupt_flagはどうやって排他制御されるデザインになっていますでしょうか?

といいますのは

1.ビットマスクとして使っているので排他制御しないとフラグがロストしてえらい事になりそう

#define RUBY_VM_SET_INTERRUPT(th) ((th)->interrupt_flag |= 0x02)
#define RUBY_VM_SET_TIMER_INTERRUPT(th) ((th)->interrupt_flag |= 0x01)
#define RUBY_VM_SET_FINALIZER_INTERRUPT(th) ((th)->interrupt_flag |= 0x04)
#define RUBY_VM_INTERRUPTED(th) ((th)->interrupt_flag & 0x02)

2.割り込み処理でフラグをリセットする箇所ではGVLしかとってない

static void
rb_threadptr_execute_interrupts_rec(rb_thread_t *th, int sched_depth)
{
(snip)

 while (th->interrupt_flag) {
     enum rb_thread_status status = th->status;
     int timer_interrupt = th->interrupt_flag & 0x01;
     int finalizer_interrupt = th->interrupt_flag & 0x04;
     th->interrupt_flag = 0;

3.タイマースレッドはTIMER_INTERRUPT bitを立てる時に、timer_thread_lock しか取ってない

static void
timer_thread_function(void *arg)
{
rb_vm_t vm = GET_VM(); / TODO: fix me for Multi-VM */

 /* for time slice */
 RUBY_VM_SET_TIMER_INTERRUPT(vm->running_thread);

4.thread.c では RUBY_VM_SET_INTERRUPT呼ぶときに thread->interrupt_lock 取るが
cont.c では取らない

5.gc.cも RUBY_VM_SET_FINALIZER_INTERRUPT 呼ぶときに特にロックを取らない

という、なかなか整合性がとれていなさそうな状況になっていそうだからです。なにか見落としていますでしょうか?

# 一瞬、すべて interrupt_lockで守るのがいいのかな。と思ったのですがよく考えたら native_mutex_lock()関数が
# thread.c 以外からは呼べないのでした。


Files

0001-interrupt-flag.patch (7.53 KB) 0001-interrupt-flag.patch kosaki (Motohiro KOSAKI), 05/23/2011 09:46 AM

Updated by kosaki (Motohiro KOSAKI) almost 13 years ago

Updated by kosaki (Motohiro KOSAKI) almost 13 years ago

  • Status changed from Assigned to Closed
Actions

Also available in: Atom PDF

Like0
Like0Like0