Alex Young
6/11/2007 4:58:00 PM
MenTaLguY wrote:
> On Tue, 12 Jun 2007 00:50:36 +0900, Alex Young <alex@blackkettle.org>
> wrote:
>>>> irb(main):006:0> a.owner = :foo NoMethodError: undefined method
>>>> `owner=' for #<Mutex:0xb788184c> from (irb):6
>
> Out of curiosity, how did it work with earlier versions of
> fastthread? fastthread never stored the current owner in @owner.
No, that was mine. I was (for various reasons) assigning owner inside a
synchronized block.
>> It's in some legacy code that broke on a gem update. It's used for
>> logging which thread's currently got the lock from inside a
>> #synchronize block. I've fixed it by changing the require order,
>> which I don't like much. It could probably be refactored out, but
>> that's not the point...
>
> Modifying Mutex isn't a very safe way to accomplish that,
> particularly as you can't rely on implementation details (because the
> implementation of Mutex is different for each Ruby implementation).
> If the owner information is important to record, you'd be much better
> off writing a wrapper around Mutex and using that instead.
To be honest, I'll probably just get rid of the code in this case, as
it's just logging execution data at this point, and it's more of a
security blanket than essential information. However, I'm not really
relying on an implementation detail here - I was adding to the
implementation by reopening the class. I should have subclassed, but
isn't the convention that we can modify classes to our own desires? I
admit that modifying a synchronisation primitive is playing with fire,
but I was purposefully not affecting its synchronisation behaviour.
Still, I understand the reason it's stopped working - it just came at a
rather inconvenient moment :-)
--
Alex