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

yarv-diff:387

From: ko1 atdot.net
Date: 5 Sep 2006 11:41:29 +0900
Subject: [yarv-diff:387] r554 - in branches/parallel: . benchmark yarvtest

Author: ko1
Date: 2006-09-05 11:41:29 +0900 (Tue, 05 Sep 2006)
New Revision: 554

Modified:
   branches/parallel/ChangeLog
   branches/parallel/benchmark/bmx_temp.rb
   branches/parallel/class.c
   branches/parallel/math.c
   branches/parallel/numeric.c
   branches/parallel/object.c
   branches/parallel/thread.c
   branches/parallel/yarvtest/test_thread.rb
Log:
	* class.c : add rb_add_method_ts, rb_define_private_method_ts, 
	_define_singleton_method_ts, rb_define_module_function_ts APIs

	* math.c : define all methods as thread safe

	* numeric.c : ditto

	* object.c : ditto

	* thread.c : fix dec wait threads num

	* yarvtest/test_thread.rb : add a test for GC



Modified: branches/parallel/ChangeLog
===================================================================
--- branches/parallel/ChangeLog	2006-09-05 00:31:52 UTC (rev 553)
+++ branches/parallel/ChangeLog	2006-09-05 02:41:29 UTC (rev 554)
@@ -4,6 +4,22 @@
 #  from Mon, 03 May 2004 01:24:19 +0900
 #
 
+2006-09-05(Tue) 11:37:11 +0900  Koichi Sasada  <ko1 atdot.net>
+
+	* class.c : add rb_add_method_ts, rb_define_private_method_ts, 
+	_define_singleton_method_ts, rb_define_module_function_ts APIs
+
+	* math.c : define all methods as thread safe
+
+	* numeric.c : ditto
+
+	* object.c : ditto
+
+	* thread.c : fix dec wait threads num
+
+	* yarvtest/test_thread.rb : add a test for GC
+
+
 2006-09-05(Tue) 09:28:37 +0900  Koichi Sasada  <ko1 atdot.net>
 
 	* gc.c : protect free/malloc/realloc with fglock

Modified: branches/parallel/benchmark/bmx_temp.rb
===================================================================
--- branches/parallel/benchmark/bmx_temp.rb	2006-09-05 00:31:52 UTC (rev 553)
+++ branches/parallel/benchmark/bmx_temp.rb	2006-09-05 02:41:29 UTC (rev 554)
@@ -1,4 +1,41 @@
+require 'complex'
 
+def mandelbrot? z
+  i = 0
+  while i<100
+    i+=1
+    z = z * z
+    return false if z.abs > 2
+  end
+  true
+end
+
+def calc
+  ary = []
+  (0..100).each{|dx|
+    (0..100).each{|dy|
+      x = dx / 50.0
+      y = dy / 50.0
+      c = Complex(x, y)
+      ary << c if mandelbrot?(c)
+    }
+  }
+end
+
+if true and false
+  (1..4).map{
+    Thread.new{
+      calc
+    }
+  }.each{|t| t.join}
+else
+  4.times{
+    calc
+  }
+end
+__END__
+
+
 class C1
   def m
     1

Modified: branches/parallel/class.c
===================================================================
--- branches/parallel/class.c	2006-09-05 00:31:52 UTC (rev 553)
+++ branches/parallel/class.c	2006-09-05 02:41:29 UTC (rev 554)
@@ -756,6 +756,13 @@
     return ary;
 }
 
+static void
+rb_add_method_ts(VALUE klass, ID name, NODE *body, int noex)
+{
+    body->u3.cnt = 1;
+    rb_add_method(klass, name, body, noex);
+}
+
 void
 rb_define_method_id(VALUE klass, ID name, VALUE (*func)(ANYARGS), int argc)
 {
@@ -771,9 +778,7 @@
 void
 rb_define_method_ts(VALUE klass, const char *name, VALUE (*func)(ANYARGS), int argc)
 {
-    NODE *node = NEW_CFUNC(func, argc);
-    node->u3.cnt = 1;
-    rb_add_method(klass, rb_intern(name), node, NOEX_PUBLIC);
+    rb_add_method_ts(klass, rb_intern(name), NEW_CFUNC(func, argc), NOEX_PUBLIC);
 }
 
 void
@@ -789,6 +794,12 @@
 }
 
 void
+rb_define_private_method_ts(VALUE klass, const char *name, VALUE (*func)(ANYARGS), int argc)
+{
+    rb_add_method(klass, rb_intern(name), NEW_CFUNC(func, argc), NOEX_PRIVATE);
+}
+
+void
 rb_undef_method(VALUE klass, const char *name)
 {
     rb_add_method(klass, rb_intern(name), 0, NOEX_UNDEF);
@@ -842,6 +853,12 @@
 }
 
 void
+rb_define_singleton_method_ts(VALUE obj, const char *name, VALUE (*func)(ANYARGS), int argc)
+{
+    rb_define_method_ts(rb_singleton_class(obj), name, func, argc);
+}
+
+void
 rb_define_module_function(VALUE module, const char *name, VALUE (*func)(ANYARGS), int argc)
 {
     rb_define_private_method(module, name, func, argc);
@@ -849,6 +866,13 @@
 }
 
 void
+rb_define_module_function_ts(VALUE module, const char *name, VALUE (*func)(ANYARGS), int argc)
+{
+    rb_define_private_method_ts(module, name, func, argc);
+    rb_define_singleton_method_ts(module, name, func, argc);
+}
+
+void
 rb_define_global_function(const char *name, VALUE (*func)(ANYARGS), int argc)
 {
     rb_define_module_function(rb_mKernel, name, func, argc);

Modified: branches/parallel/math.c
===================================================================
--- branches/parallel/math.c	2006-09-05 00:31:52 UTC (rev 553)
+++ branches/parallel/math.c	2006-09-05 02:41:29 UTC (rev 554)
@@ -449,6 +449,7 @@
  *  define Ruby's floating point accuracy.
  */     
 
+#define rb_define_module_function rb_define_module_function_ts
 
 void
 Init_Math(void)

Modified: branches/parallel/numeric.c
===================================================================
--- branches/parallel/numeric.c	2006-09-05 00:31:52 UTC (rev 553)
+++ branches/parallel/numeric.c	2006-09-05 02:41:29 UTC (rev 554)
@@ -2810,6 +2810,8 @@
     return Qfalse;
 }
 
+#define rb_define_method rb_define_method_ts
+
 void
 Init_Numeric(void)
 {

Modified: branches/parallel/object.c
===================================================================
--- branches/parallel/object.c	2006-09-05 00:31:52 UTC (rev 553)
+++ branches/parallel/object.c	2006-09-05 02:41:29 UTC (rev 554)
@@ -2386,6 +2386,8 @@
  *  <code>Symbol</code> (such as <code>:name</code>).
  */
 
+#define rb_define_method rb_define_method_ts
+
 void
 Init_Object(void)
 {

Modified: branches/parallel/thread.c
===================================================================
--- branches/parallel/thread.c	2006-09-05 00:31:52 UTC (rev 553)
+++ branches/parallel/thread.c	2006-09-05 02:41:29 UTC (rev 554)
@@ -137,6 +137,15 @@
 }
 #endif
 
+#if 0
+#define check(vm) (vm->num_wait_threads < 0 ? (printf("err: %d", __LINE__), exit(1)) : 0)
+#define INC_WAIT_THREAD(vm) (printf("wt(+:%d:%p): %d\n", __LINE__, pthread_self(), ++vm->num_wait_threads), check(vm))
+#define DEC_WAIT_THREAD(vm) (printf("wt(-:%d:%p): %d\n", __LINE__, pthread_self(), --vm->num_wait_threads), check(vm))
+#else
+#define INC_WAIT_THREAD(vm) ((vm)->num_wait_threads++)
+#define DEC_WAIT_THREAD(vm) ((vm)->num_wait_threads--)
+#endif
+
 static int profile_confilict;
 static void __attribute__((destructor))
      pr_show(void)
@@ -180,7 +189,7 @@
 	    
 	    native_mutex_lock(&vm->gc_lock);
 	    {
-		vm->num_wait_threads++;
+		INC_WAIT_THREAD(vm);
 		if (vm->interrupt_gc_flag) {
 		    native_cond_signal(&vm->gc_barrier_owner_cond);
 		}
@@ -192,9 +201,10 @@
 
 	    native_mutex_lock(&vm->gc_lock);
 	    {
-		vm->num_wait_threads--;
+		DEC_WAIT_THREAD(vm);
+
 		if (vm->interrupt_gc_flag) {
-		    rb_bug("...?");
+		    rb_bug("bug?");
 		}
 	    }
 	    native_mutex_unlock(&vm->gc_lock);
@@ -247,7 +257,8 @@
 
     native_mutex_lock(&vm->gc_lock);
     {
-	vm->num_wait_threads++;
+	INC_WAIT_THREAD(vm);
+	
 	if (vm->interrupt_gc_flag) {
 	    native_cond_signal(&vm->gc_barrier_owner_cond);
 	}
@@ -262,14 +273,14 @@
 rb_thread_blocking_end(yarv_thread_t *th)
 {
     yarv_vm_t *vm = GET_VM();
+    yarv_clear_interrupt_function(th);
 
     native_mutex_lock(&vm->gc_lock);
     {
-	vm->num_wait_threads--;
+	DEC_WAIT_THREAD(vm);
     }
     native_mutex_unlock(&vm->gc_lock);
     
-    yarv_clear_interrupt_function(th);
     rb_thread_global_lock_acquire(th);
 }
 
@@ -286,13 +297,15 @@
 	if (vm->interrupt_gc_flag) {
 	    native_mutex_lock(&vm->gc_lock);
 	    {
-		vm->num_wait_threads++;
-		thread_debug("rb_thread_gc_barrier_stop: waiting -> %d\n",
-			     vm->num_wait_threads);
-		native_cond_signal(&vm->gc_barrier_owner_cond);
-		native_cond_wait(&vm->gc_barrier_waits_cond,
-				 &vm->gc_lock);
-		vm->num_wait_threads--;
+		INC_WAIT_THREAD(vm);
+		{
+		    thread_debug("rb_thread_gc_barrier_stop: waiting -> %d\n",
+				 vm->num_wait_threads);
+		    native_cond_signal(&vm->gc_barrier_owner_cond);
+		    native_cond_wait(&vm->gc_barrier_waits_cond,
+				     &vm->gc_lock);
+		}
+		DEC_WAIT_THREAD(vm);
 	    }
 	    native_mutex_unlock(&vm->gc_lock);
 	}
@@ -755,9 +768,9 @@
 
 	YARV_CHECK_INTS();
 #else
-	rb_thread_blocking_start(th, 0);
-	native_thread_yield();
-	rb_thread_blocking_end(th);
+	BLOCKING_RANGE(th, 0, {
+	    native_thread_yield();
+	});
 #endif
     }
 }
@@ -2130,7 +2143,6 @@
 	/* can't cancel */
 	BLOCKING_RANGE(th, 0, {
 	    native_mutex_lock(&mutex->lock);
-	    rb_thread_blocking_end(th);
 	});
     }
 

Modified: branches/parallel/yarvtest/test_thread.rb
===================================================================
--- branches/parallel/yarvtest/test_thread.rb	2006-09-05 00:31:52 UTC (rev 553)
+++ branches/parallel/yarvtest/test_thread.rb	2006-09-05 02:41:29 UTC (rev 554)
@@ -41,6 +41,27 @@
       :ok
     }
   end
+
+  def test_threads_with_gc2
+    ae %q{
+      Thread.new{
+        loop{
+          GC.start
+          Thread.pass
+        }
+      }
+      
+      Thread.new{
+        loop{
+          s = 'abc'
+          100.times{
+            s << 'f'
+          }
+        }
+      }
+      sleep 1
+    }
+  end
   
   def test_create_many_threads1
     ae %q{


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

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