[Win32utils-devel] Trying to get a good example for win32-mutex

Berger, Daniel Daniel.Berger at qwest.com
Fri May 4 10:57:03 EDT 2007


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.


More information about the win32utils-devel mailing list