From 0e3b0fcdba70cf96a8e0654eb8f50aacb8024bd4 Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Thu, 14 May 2020 22:10:55 +1200 Subject: Thread scheduler for light weight concurrency. --- vm.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'vm.c') diff --git a/vm.c b/vm.c index 6f9c999adb..d286bc7210 100644 --- a/vm.c +++ b/vm.c @@ -2620,6 +2620,8 @@ thread_mark(void *ptr) RUBY_MARK_UNLESS_NULL(th->locking_mutex); RUBY_MARK_UNLESS_NULL(th->name); + RUBY_MARK_UNLESS_NULL(th->scheduler); + RUBY_MARK_LEAVE("thread"); } @@ -2734,6 +2736,10 @@ th_init(rb_thread_t *th, VALUE self) th->self = self; rb_threadptr_root_fiber_setup(th); + /* All threads are blocking until a non-blocking fiber is scheduled */ + th->blocking = 1; + th->scheduler = Qnil; + if (self == 0) { size_t size = th->vm->default_params.thread_vm_stack_size / sizeof(VALUE); rb_ec_initialize_vm_stack(th->ec, ALLOC_N(VALUE, size), size); @@ -3294,12 +3300,14 @@ Init_VM(void) vm->self = TypedData_Wrap_Struct(rb_cRubyVM, &vm_data_type, vm); /* create main thread */ - th->self = TypedData_Wrap_Struct(rb_cThread, &thread_data_type, th); + th->self = TypedData_Wrap_Struct(rb_cThread, &thread_data_type, th); + vm->main_thread = th; vm->running_thread = th; th->vm = vm; th->top_wrapper = 0; th->top_self = rb_vm_top_self(); + rb_thread_set_current(th); rb_vm_living_threads_insert(vm, th); -- cgit v1.2.3