Permalink
Browse files

* thread.c: fix Mutex to be interruptable lock.

* thread_win32.ci, thread_win32.h, thread_pthread.ci, thread_pthread.h:
  prepare native_cond_*() which are based on pthread_cond_*() spec.
* prelude.rb: fix Mutex#synchronize method.
* vm_core.h, include/ruby/intern.h: change unblock function interface
  (to pass some user data).
* file.c, process.c: ditto.
* benchmark/bm_vm2_mutex.rb: add a benchmark for mutex.
* benchmark/bm_vm3_thread_mutex.rb: add a benchmark for mutex
  with contension.
* benchmark/run.rb: fix to remove ENV['RUBYLIB'] for matzruby.
* test/ruby/test_thread.rb: add a test.
* common.mk: fix benchmark options.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13290 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
ko1 committed Aug 27, 2007
1 parent 51fb551 commit 6244e502cc12a7b8c5698740d3b5b355c1695e37
View
@@ -1,3 +1,28 @@
+Tue Aug 28 00:51:22 2007 Koichi Sasada <ko1@atdot.net>
+
+ * thread.c: fix Mutex to be interruptable lock.
+
+ * thread_win32.ci, thread_win32.h, thread_pthread.ci, thread_pthread.h:
+ prepare native_cond_*() which are based on pthread_cond_*() spec.
+
+ * prelude.rb: fix Mutex#synchronize method.
+
+ * vm_core.h, include/ruby/intern.h: change unblock function interface
+ (to pass some user data).
+
+ * file.c, process.c: ditto.
+
+ * benchmark/bm_vm2_mutex.rb: add a benchmark for mutex.
+
+ * benchmark/bm_vm3_thread_mutex.rb: add a benchmark for mutex
+ with contension.
+
+ * benchmark/run.rb: fix to remove ENV['RUBYLIB'] for matzruby.
+
+ * test/ruby/test_thread.rb: add a test.
+
+ * common.mk: fix benchmark options.
+
Mon Aug 27 23:14:02 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
* string.c (rb_str_rstrip_bang): wrong strip point. [ruby-dev:31652]
@@ -29,6 +54,7 @@ Mon Aug 27 15:56:48 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* string.c (sym_encoding): return the encoding of a Symbol.
+>>>>>>> .r13289
Mon Aug 27 15:33:10 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* util.c (IEEE_BIG_ENDIAN): use configured value. [ruby-dev:31623]
@@ -1,14 +1,14 @@
-max = 600000
-
-if defined? Fiber
- gen = (1..max).each
- loop do
- gen.next
- end
-else
- require 'generator'
- gen = Generator.new((0..max))
- while gen.next?
- gen.next
- end
-end
+max = 600000
+
+if defined? Fiber
+ gen = (1..max).each
+ loop do
+ gen.next
+ end
+else
+ require 'generator'
+ gen = Generator.new((0..max))
+ while gen.next?
+ gen.next
+ end
+end
View
@@ -1,14 +1,14 @@
-i=0
-while i<6000000 # while loop 2
- case :foo
- when :bar
- raise
- when :baz
- raise
- when :boo
- raise
- when :foo
- i+=1
- end
-end
-
+i=0
+while i<6000000 # while loop 2
+ case :foo
+ when :bar
+ raise
+ when :baz
+ raise
+ when :boo
+ raise
+ when :foo
+ i+=1
+ end
+end
+
@@ -0,0 +1,9 @@
+require 'thread'
+
+m = Mutex.new
+
+i=0
+while i<6000000 # benchmark loop 2
+ i+=1
+ m.synchronize{}
+end
@@ -0,0 +1,18 @@
+require 'thread'
+m = Mutex.new
+r = 0
+max = 1000
+(1..max).map{
+ Thread.new{
+ i=0
+ while i<max
+ i+=1
+ m.synchronize{
+ r += 1
+ }
+ end
+ }
+}.each{|e|
+ e.join
+}
+raise r.to_s if r != max * max
View
No changes.
View
@@ -68,7 +68,11 @@ def ruby_exec file
def matzruby_exec file
print 'matz'
- benchmark file, $matzruby_program
+ rubylib = ENV['RUBYLIB']
+ ENV['RUBYLIB'] = ''
+ r = benchmark file, $matzruby_program
+ ENV['RUBYLIB'] = rubylib
+ r
end
if $0 == __FILE__
View
@@ -655,10 +655,10 @@ parse: miniruby$(EXEEXT) PHONY
$(MINIRUBY) $(srcdir)/tool/parse.rb $(srcdir)/test.rb
benchmark: $(PROGRAM) PHONY
- $(RUNRUBY) $(srcdir)/benchmark/run.rb $(OPT) $(ITEMS) --ruby=./$(PROGRAM) --matzruby=$(MATZRUBY) --opts=-I$(srcdir)/lib
+ $(RUNRUBY) $(srcdir)/benchmark/run.rb $(OPT) $(ITEMS) --ruby=`./$(PROGRAM) -I$(srcdir)/lib' --matzruby=$(MATZRUBY)
benchmark-each: $(PROGRAM) PHONY
- $(RUNRUBY) $(srcdir)/benchmark/run.rb bm_$(ITEM) $(OPT) --ruby=./$(PROGRAM) --matzruby=$(MATZRUBY) --opts=-I$(srcdir)/lib
+ $(RUNRUBY) $(srcdir)/benchmark/run.rb bm_$(ITEM) $(OPT) --ruby='./$(PROGRAM) -I$(srcdir)/lib' --matzruby=$(MATZRUBY)
tbench: $(PROGRAM) PHONY
$(RUNRUBY) $(srcdir)/benchmark/run.rb bmx $(OPT) --ruby=./$(PROGRAM) --matzruby=$(MATZRUBY) --opts=-I$(srcdir)/lib
View
2 file.c
@@ -3148,7 +3148,7 @@ rb_file_flock(VALUE obj, VALUE operation)
if (fptr->mode & FMODE_WRITABLE) {
rb_io_flush(obj);
}
- while ((int)rb_thread_blocking_region(rb_thread_flock, op, RB_UBF_DFL) < 0) {
+ while ((int)rb_thread_blocking_region(rb_thread_flock, op, RB_UBF_DFL, 0) < 0) {
switch (errno) {
case EAGAIN:
case EACCES:
View
@@ -533,10 +533,10 @@ VALUE rb_struct_s_members(VALUE);
VALUE rb_struct_members(VALUE);
/* thread.c */
typedef struct rb_thread_struct rb_thread_t;
-typedef void rb_unblock_function_t(rb_thread_t *);
+typedef void rb_unblock_function_t(rb_thread_t *, void *);
typedef VALUE rb_blocking_function_t(rb_thread_t *th, void *);
-VALUE rb_thread_blocking_region(rb_blocking_function_t *func, void *data,
- rb_unblock_function_t *ubf);
+VALUE rb_thread_blocking_region(rb_blocking_function_t *func, void *data1,
+ rb_unblock_function_t *ubf, void *data2);
#define RB_UBF_DFL ((rb_unblock_function_t *)-1)
VALUE rb_mutex_new(void);
VALUE rb_mutex_locked_p(VALUE mutex);
View
@@ -4,9 +4,11 @@
class Mutex
def synchronize
self.lock
- yield
- ensure
- self.unlock
+ begin
+ yield
+ ensure
+ self.unlock
+ end
end
end
View
@@ -606,8 +606,8 @@ rb_waitpid(rb_pid_t pid, int *st, int flags)
arg.st = st;
arg.flags = flags;
retry:
- result = (rb_pid_t)rb_thread_blocking_region(rb_waitpid_blocking,
- &arg, RB_UBF_DFL);
+ result = (rb_pid_t)rb_thread_blocking_region(rb_waitpid_blocking, &arg,
+ RB_UBF_DFL, 0);
if (result < 0) {
#if 0
if (errno == EINTR) {
View
@@ -0,0 +1,24 @@
+require 'test/unit'
+
+class TestThread < Test::Unit::TestCase
+ def test_mutex_synchronize
+ m = Mutex.new
+ r = 0
+ max = 100
+ (1..max).map{
+ Thread.new{
+ i=0
+ while i<max*max
+ i+=1
+ m.synchronize{
+ r += 1
+ }
+ end
+ }
+ }.each{|e|
+ e.join
+ }
+ assert_equal(max * max * max, r)
+ end
+end
+
Oops, something went wrong.

0 comments on commit 6244e50

Please sign in to comment.