[前][次][番号順一覧][スレッド一覧][生データ]

yarv-diff:115

From: ko1 atdot.net
Date: 1 Oct 2005 16:24:50 -0000
Subject: [yarv-diff:115] r271 - trunk

Author: ko1
Date: 2005-10-02 01:24:49 +0900 (Sun, 02 Oct 2005)
New Revision: 271

Modified:
   trunk/ChangeLog
   trunk/test.rb
   trunk/thread.c
Log:
	* thread.c : add raw gets (for test), and fix indent



Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2005-10-01 14:09:59 UTC (rev 270)
+++ trunk/ChangeLog	2005-10-01 16:24:49 UTC (rev 271)
@@ -4,6 +4,11 @@
 #  from Mon, 03 May 2004 01:24:19 +0900
 #
 
+2005-10-02(Sun) 01:23:44 +0900  Koichi Sasada  <ko1 atdot.net>
+
+	* thread.c : add raw gets (for test), and fix indent
+
+
 2005-10-01(Sat) 23:06:21 +0900  Koichi Sasada  <ko1 atdot.net>
 
 	* thread_win32.h, common.mk : add thread_win32.h

Modified: trunk/test.rb
===================================================================
--- trunk/test.rb	2005-10-01 14:09:59 UTC (rev 270)
+++ trunk/test.rb	2005-10-01 16:24:49 UTC (rev 271)
@@ -1,5 +1,17 @@
+i=0
+Thread.new{
+  loop{
+    sleep 0.1
+    p i+=1 % 10
+  }
+}
 
 Thread.new{
+  p raw_gets
+}.join
+
+__END__
+Thread.new{
   100.times{|i|
     sleep 1
     p [i]

Modified: trunk/thread.c
===================================================================
--- trunk/thread.c	2005-10-01 14:09:59 UTC (rev 270)
+++ trunk/thread.c	2005-10-01 16:24:49 UTC (rev 271)
@@ -90,14 +90,16 @@
   th->machine_stack_start = stack_start;
   
   thread_debug("start: %p\n", th);
+  
   GVL_LOCK_BEGIN();
-  yarv_set_current_running_thread(th);
-  thread_debug("get_lock, start: %p\n", th);
-  th->value = th_invoke_proc(th, proc, RARRAY(args)->len, RARRAY(args)->ptr);
-  th->status = THREAD_KILLED;
-  thread_debug("end: %p\n", th);
-  st_delete_wrap(GET_VM()->living_threads, th->self);
-
+  {
+    yarv_set_current_running_thread(th);
+    thread_debug("get_lock, start: %p\n", th);
+    th->value = th_invoke_proc(th, proc, RARRAY(args)->len, RARRAY(args)->ptr);
+    th->status = THREAD_KILLED;
+    thread_debug("end: %p\n", th);
+    st_delete_wrap(GET_VM()->living_threads, th->self);
+  }
   GVL_LOCK_END();
 
   return 0;
@@ -136,8 +138,11 @@
 
   if(argc == 0){
     thread_debug("yarv_thread_join(0)\n");
+    
     GVL_UNLOCK_BEGIN();
-    err = native_thread_join(th->thread_id, 0);
+    {
+      err = native_thread_join(th->thread_id, 0);
+    }
     GVL_UNLOCK_END();
 
     switch(err){
@@ -155,7 +160,9 @@
     
     while(1){
       GVL_UNLOCK_BEGIN();
-      sleep_for_polling();
+      {
+        sleep_for_polling();
+      }
       GVL_UNLOCK_END();
       
       if(th->status == THREAD_KILLED){
@@ -195,7 +202,9 @@
 {
   thread_debug("rb_thread_sleep_forever\n");
   GVL_UNLOCK_BEGIN();
-  pause();
+  {
+    pause();
+  }
   GVL_UNLOCK_END();
 }
 
@@ -265,9 +274,13 @@
   double date;
   thread_debug("rb_thread_wait_for\n");
   CSL_UNLOCK_BEGIN();
-  GVL_UNLOCK_BEGIN();
-  sleep_timeval(time);
-  GVL_UNLOCK_END();
+  {
+    GVL_UNLOCK_BEGIN();
+    {
+      sleep_timeval(time);
+    }
+    GVL_UNLOCK_END();
+  }
   CSL_UNLOCK_END();
 }
 
@@ -281,6 +294,10 @@
     thread_debug("yarv_thraed_schedule/switch\n");
     yarv_save_machine_context(th);
     native_mutex_unlock(&GET_VM()->global_interpreter_lock);
+    {
+      /* do nothing. */
+      /* will be switch to another thread which is trying to acquire GVL */
+    }
     native_mutex_lock(&GET_VM()->global_interpreter_lock);
     yarv_set_current_running_thread(th);
   }
@@ -465,9 +482,20 @@
   setjmp(th->machine_regs);
 }
 
+static VALUE
+raw_gets(VALUE klass){
+  char buff[100];
+  GVL_UNLOCK_BEGIN();
+  {
+    fgets(buff, 100, stdin);
+  }
+  GVL_UNLOCK_END();
+  return rb_str_new2(buff);
+}
 
 void
 Init_yarvthread(){
+  rb_define_global_function("raw_gets", raw_gets, 0);
   rb_define_singleton_method(cYarvThread, "new", yarv_thread_s_new, -2);
   rb_define_singleton_method(cYarvThread, "start", yarv_thread_s_new, -2);
   rb_define_singleton_method(cYarvThread, "fork", yarv_thread_s_new, -2);


--
ML: yarv-diff quickml.atdot.net
Info: http://www.atdot.net/~ko1/quickml

[前][次][番号順一覧][スレッド一覧][生データ]