From: "Firestone, Mark - Technical Support" Date: 2002-03-15T19:15:33+09:00 Subject: RE: Newbie -- Please help!! Ok. I understand WHAT you mean... I just don't know how to get there (nor can I find a sample to show me the way...) to get from where I am (see code fragment below..) and where I need to be.. being able to share this object among many threads... the only way I have managed to set it up at present... each thread would be creating it's own instance of the object.... not what I want to do at all. I want each thread to share ONE instance of the object with locking... thanks for putting up with my ignorance! Humbly, mark class User_list include Enumerable def initialize @users = Array.new end def append(aUser) @users.push(aUser) self end def [](key) if key.kind_of?(Integer) result = @users[key] else result = @users.find { |user| key == user.name } end return result end ## end #of Class User_list ## class method of User_list, so we don't need instance. def self.loadusers list = nil File.open("users.dat") do |f| list = Marshal.load(f) ## print "- Loading User Object...\n" end return list ## end # save list def saveusers File.open("users.dat", "w+") do |f| Marshal.dump( self, f) ## end print "- Saving User Object...\n" end def checkpassword (username,password) result = FALSE if self[username] != nil ## if self[username].password == password ## result = TRUE end else print "\n-Bad username passed to def:checkpassword. Please tell sysop!\n" end return result end ## new end... end #of Class User_list class Session require 'thread' @@busy = Mutex.new # Perhaps we'll find another way to pass the socket. # For now, a default value of "nil" will make it OK # for ConsoleIO. def initialize(socket = nil) @socket = socket @list = User_list.new end def open_userfile if File.exists?("users.dat") @list = User_list.loadusers else @list = User_list.new @list.append(User.new('SYSOP','000-000-0000','Tempe, AZ','600 E. Solana Drive','STUPID')) @list.append(User.new('TEST','000-000-0000','Mesa, AZ','123 Sample Street','HAPPY')) print "- User File not Found. Creating new User File\n" end end def login write 255.chr #this seems to stop telnet clients that want to echo write 254.chr #from echoing. move this to it's own def later write 1.chr putstr putstr "TOPquark 1.2r (c) 1993 by TOPsoftware" putstr IO.foreach("welcome1.txt") { |line| putstr line } done = FALSE count = 0 until (done) write "Enter your name: " userName = getstr(true).strip.upcase if @list[userName] != nil write "Password: " password = getstr(false).strip.upcase if @list.checkpassword(userName,password) == TRUE done = TRUE end else write "#{userName} right? (Y,n)" answer =getstr(true).strip.upcase if (answer == !nil) or (answer == 'Y') write "Enter a password: " pswd = getstr(false).strip.upcase @list.append(User.new(userName,'000-000-0000','A Location','An Address',pswd)) @list.saveusers done = TRUE end end end #of Until (Done) putstr putstr "Congratulations. You have been granted the privilege" putstr "of entry into the system by Microsoft's* certified," putstr "better-than-yours-because-we-said-so security." putstr putstr "* Microsoft(r) is a registered trademark of a company" putstr "with way more lawyers than me." putstr end def readmsgs users = ["BIG BEN", "SHO KOSUGI", "GLENN", "CAPTAIN CRUNCH", "PEE-WEE HERMAN", "SUE WIDEMARK", "TINA"] subjects = ["Ev Mecham", "Atari Roolz!", "Call my board!", "Please don't delete me!", "Where's the file board?"] putstr "From: " + pick_one(users) putstr "To: ALL" putstr "Subj: " + pick_one(subjects) putstr putstr "Hello, world!" putstr putstr "END OF MESSAGES" end -----Original Message----- From: Olonichev Sergei [mailto:olonichev@scnsoft.com] Sent: 14 March 2002 15:11 To: ruby-talk@ruby-lang.org Subject: Re: Newbie -- Please help!! Easier saing you must not have objects which can be modified at the same time from diffrent threads, If you have to you should use critical sections. And it does not matter whether these objects are global or not. To avoid using global objects is a good practice. NOTICE: This e-mail and any attachment(s) may contain confidential and proprietary information of Goss International Corporation and/or its subsidiaries and may be legally privileged. This e-mail is intended solely for the addressee. If you are not the addressee, dissemination, copying or other use of this e-mail or any of its content is strictly prohibited and may be unlawful. If you are not the intended recipient please inform the sender immediately and destroy the e-mail and any copies. All liability for viruses is excluded to the fullest extent permitted by law. Any views expressed in this message are those of the individual sender. No contract may be construed by this e-mail.