# Mutex question

**URL:** <https://www.ruby-forum.com/t/mutex-question/137972>\
**Category:** Ruby\
**Created:** [May 19, 2008, 4:22am UTC](https://www.ruby-forum.com/t/mutex-question/137972 "2008-05-19T04:22:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![snowdall](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/45deac/32.png) [@snowdall](https://www.ruby-forum.com/u/snowdall)\
**Post date:** [May 19, 2008, 4:22am UTC](https://www.ruby-forum.com/t/mutex-question/137972/1 "2008-05-19T04:22:29Z")

</div>

Ok … I’m not sure what the story is with this (perhaps I’m just  
clueless). But, when I do this:

class MutexTest  
def initialize  
@lock = Mutex.new  
end  
end

test = MutexTest.new

I get this:

mutex\_test.rb:3:in `initialize': uninitialized constant MutexTest::Mutex (NameError) from mutex_test.rb:7:in`new’  
from mutex\_test.rb:7

But if I do THIS:

require ‘rubygems’  
require ‘fastthread’

class MutexTest  
def initialize  
@lock = Mutex.new  
end  
end

test = MutexTest.new

It works fine. Am I missing something? I’ve been working out of the  
pickax book and it mentions nothing of this. Side note: ruby version  
1.8.6, gem version 1.1.1, running on Mac OS X 1.5.2 (with Apples builtin  
ruby).

Any ideas?

Thanks for the help,  
Snowdall

---

<div class="post-metadata">

**Author:** ![snowdall](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/45deac/32.png) [@snowdall](https://www.ruby-forum.com/u/snowdall)\
**Post date:** [May 19, 2008, 5:18am UTC](https://www.ruby-forum.com/t/mutex-question/137972/2 "2008-05-19T05:18:39Z")

</div>

Clark S. wrote:

> Ok … I’m not sure what the story is with this (perhaps I’m just  
> clueless). But, when I do this:
> 
> class MutexTest  
> def initialize  
> @lock = Mutex.new  
> end  
> end
> 
> test = MutexTest.new
> 
> I get this:
> 
> mutex\_test.rb:3:in `initialize': uninitialized constant MutexTest::Mutex (NameError) from mutex_test.rb:7:in`new’  
> from mutex\_test.rb:7

m = Mutex.new  
puts ‘hello’

–output:–  
1: uninitialized constant Mutex (NameError)

* * *

require ‘thread’  
m = Mutex.new  
puts ‘hello’

–output:–  
hello

See pickaxe2, p 696.

---

<div class="post-metadata">

**Author:** ![snowdall](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/45deac/32.png) [@snowdall](https://www.ruby-forum.com/u/snowdall)\
**Post date:** [May 19, 2008, 9:03am UTC](https://www.ruby-forum.com/t/mutex-question/137972/3 "2008-05-19T09:03:17Z")

</div>

7stud – wrote:

> Clark S. wrote:
> 
> > Ok … I’m not sure what the story is with this (perhaps I’m just  
> > clueless). But, when I do this:
> > 
> > class MutexTest  
> > def initialize  
> > @lock = Mutex.new  
> > end  
> > end
> > 
> > test = MutexTest.new
> > 
> > I get this:
> > 
> > mutex\_test.rb:3:in `initialize': uninitialized constant MutexTest::Mutex (NameError) from mutex_test.rb:7:in`new’  
> > from mutex\_test.rb:7
> 
> require ‘thread’  
> m = Mutex.new  
> puts ‘hello’
> 
> –output:–  
> hello
> 
> See pickaxe2, p 696.

Also:

require ‘thread’

arr = Object.constants  
results = arr.find\_all{|name| name[0,1]==“M”}  
p results

–outuput:–  
[“Marshal”, “Math”, “Method”, “MatchingData”, “Mutex”, “MatchData”,  
“Module”]
