Berger, Daniel
2007-May-04 14:57 UTC
[Win32utils-devel] Trying to get a good example for win32-mutex
Hi all,
I''ve been going through the various IPC modules for Win32Utils and
converting them to pure Ruby. I''m almost done with win32-mutex, but I
can''t get the example to work. I keep getting this error:
C:/Documents and
Settings/djberge/workspace/win32-mutex/examples/mutex_test.rb:41:
undefined method `+'' for nil:NilClass
(NoMethodError)
from C:/Documents and
Settings/djberge/workspace/win32-mutex/examples/mutex_test.rb:38:in
`times''
from C:/Documents and
Settings/djberge/workspace/win32-mutex/examples/mutex_test.rb:38
Here''s the updated mutex_test.rb file. I''m using the
win32/mutex.rb file
in CVS, win32-mmap 0.2.1 and win32-process 0.5.2:
##############################################################
# mutex_test.rb
#
# A test script for general futzing. Modify as you see fit.
# This test script requires win32-process and win32-mmap.
##############################################################
MUTEXNAME = "This is a very long name"
require ''win32/mutex''
require ''win32/process''
require ''win32/mmap''
include Win32
pid = Process.fork
# child_1
if pid.nil?
mm = MMap.open(''test'')
mx = Win32::Mutex.open(MUTEXNAME)
5.times{
mx.wait
puts "child_1 wait "
mm.gvalue += 123
sleep 1
mm.gvalue -= 123
mx.release
puts "child_1 release "
}
exit 1
end
pid2 = Process.fork
# child_2
if pid2.nil?
mm = MMap.open(''test'')
mx = Win32::Mutex.open(MUTEXNAME)
4.times{
mx.wait
puts "child_2 wait "
mm.gvalue += 456
sleep 2
mm.gvalue -= 456
mx.release
puts "child_2 release "
}
exit 1
end
#parent
mm = MMap.new(:size => 1024, :name => ''test'', :inherit
=> true)
mm.gvalue = 0
mx = Win32::Mutex.new(true, MUTEXNAME) # named mutex object
3.times{
mx.wait
puts "parent wait"
sleep 5
printf("Value of GValue=%d\n", mm.gvalue)
mx.release
puts "parent release"
}
p Process.waitpid2(pid)
p Process.waitpid2(pid2)
It looks like the MMap.open(''test'') is working fine, but
it''s not
picking up the gvalue set in the parent for some reason.
Any ideas?
Thanks,
Dan
This communication is the property of Qwest and may contain confidential or
privileged information. Unauthorized use of this communication is strictly
prohibited and may be unlawful. If you have received this communication
in error, please immediately notify the sender by reply e-mail and destroy
all copies of the communication and any attachments.
Berger, Daniel
2007-May-04 15:08 UTC
[Win32utils-devel] Trying to get a good example for win32-mutex
> -----Original Message----- > From: win32utils-devel-bounces at rubyforge.org > [mailto:win32utils-devel-bounces at rubyforge.org] On Behalf Of > Berger, Daniel > Sent: Friday, May 04, 2007 8:57 AM > To: Development and ideas for win32utils projects > Subject: [Win32utils-devel] Trying to get a good example for > win32-mutex > > > Hi all, > > I''ve been going through the various IPC modules for > Win32Utils and converting them to pure Ruby. I''m almost done > with win32-mutex, but I can''t get the example to work. I > keep getting this error: > > C:/Documents and > Settings/djberge/workspace/win32-mutex/examples/mutex_test.rb:41: > undefined method `+'' for nil:NilClass > (NoMethodError) > from C:/Documents and > Settings/djberge/workspace/win32-mutex/examples/mutex_test.rb:38:in > `times'' > from C:/Documents and > Settings/djberge/workspace/win32-mutex/examples/mutex_test.rb:38 > > Here''s the updated mutex_test.rb file. I''m using the > win32/mutex.rb file in CVS, win32-mmap 0.2.1 and win32-process 0.5.2:<snip> Further review indicates that the problem is setting attributes to a value of zero. I fired up two irb sessions, creating an mmap in one and opening it in the other. When I do "mm.gvalue = 5", everything works alright. However, if I set it to 0, I start getting: ArgumentError: marshal data too short from C:/ruby/lib/ruby/gems/1.8/gems/win32-mmap-0.2.0/lib/win32/mmap.rb:335:in `load'' from C:/ruby/lib/ruby/gems/1.8/gems/win32-mmap-0.2.0/lib/win32/mmap.rb:335:in `method_missing'' from (irb):7 So, looks like a bug in win32-mmap. Disregard. Dan This communication is the property of Qwest and may contain confidential or privileged information. Unauthorized use of this communication is strictly prohibited and may be unlawful. If you have received this communication in error, please immediately notify the sender by reply e-mail and destroy all copies of the communication and any attachments.