From: Nobuyoshi Nakada Date: 2002-05-31T23:52:49+09:00 Subject: Re: Thread safe array Hi, At Fri, 31 May 2002 22:53:20 +0900, Dossy wrote: > Out of paranoia (and because I don't know how Mutex#lock is > implemented) I might be inclined to do: > > > def method_missing(method, *args, &block) > > begin > > @mutex.lock > > @internalArray.send(method, *args, &block) > > ensure > > @mutex.unlock > > end > > end > > Move the lock inside the begin/ensure/end block. This way, > you don't have a case where Mutex#lock fails throwing an > exception but you still access the array. def method_missing(method, *args, &block) @mutex.synchronize do @internalArray.send(method, *args, &block) end end -- Nobu Nakada