[#15707] Schedule for the 1.8.7 release — "Akinori MUSHA" <knu@...>

Hi, developers,

21 messages 2008/03/01

[#15740] Copy-on-write friendly garbage collector — Hongli Lai <hongli@...99.net>

Hi.

31 messages 2008/03/03
[#15742] Re: Copy-on-write friendly garbage collector — Yukihiro Matsumoto <matz@...> 2008/03/03

Hi,

[#15829] Re: Copy-on-write friendly garbage collector — Daniel DeLorme <dan-ml@...42.com> 2008/03/08

Yukihiro Matsumoto wrote:

[#15756] embedding Ruby 1.9.0 inside pthread — "Suraj Kurapati" <sunaku@...>

Hello,

18 messages 2008/03/03
[#15759] Re: embedding Ruby 1.9.0 inside pthread — Nobuyoshi Nakada <nobu@...> 2008/03/04

Hi,

[#15760] Re: embedding Ruby 1.9.0 inside pthread — Yukihiro Matsumoto <matz@...> 2008/03/04

Hi,

[#15762] Re: embedding Ruby 1.9.0 inside pthread — "Suraj N. Kurapati" <sunaku@...> 2008/03/04

Yukihiro Matsumoto wrote:

[#15783] Adding startup and shutdown to Test::Unit — Daniel Berger <Daniel.Berger@...>

Hi all,

15 messages 2008/03/04

[#15835] TimeoutError in core, timeouts for ConditionVariable#wait — MenTaLguY <mental@...>

I've been reworking JRuby's stdlib to improve performance and fix

10 messages 2008/03/09

[#15990] Recent changes in Range#step behavior — "Vladimir Sizikov" <vsizikov@...>

Hi,

35 messages 2008/03/23
[#15991] Re: Recent changes in Range#step behavior — Dave Thomas <dave@...> 2008/03/23

[#15993] Re: Recent changes in Range#step behavior — "Vladimir Sizikov" <vsizikov@...> 2008/03/23

Hi Dave,

[#15997] Re: Recent changes in Range#step behavior — Dave Thomas <dave@...> 2008/03/23

[#16024] Re: Recent changes in Range#step behavior — "Vladimir Sizikov" <vsizikov@...> 2008/03/26

Hi Dave,

[#16025] Re: Recent changes in Range#step behavior — Yukihiro Matsumoto <matz@...> 2008/03/26

Hi,

[#16026] Re: Recent changes in Range#step behavior — Dave Thomas <dave@...> 2008/03/26

[#16027] Re: Recent changes in Range#step behavior — Yukihiro Matsumoto <matz@...> 2008/03/26

Hi,

[#16029] Re: Recent changes in Range#step behavior — Dave Thomas <dave@...> 2008/03/26

[#16030] Re: Recent changes in Range#step behavior — Yukihiro Matsumoto <matz@...> 2008/03/26

Hi,

[#16031] Re: Recent changes in Range#step behavior — Dave Thomas <dave@...> 2008/03/26

[#16032] Re: Recent changes in Range#step behavior — "Vladimir Sizikov" <vsizikov@...> 2008/03/26

On Wed, Mar 26, 2008 at 7:01 PM, Dave Thomas <dave@pragprog.com> wrote:

[#16033] Re: Recent changes in Range#step behavior — Dave Thomas <dave@...> 2008/03/26

[#16041] Re: Recent changes in Range#step behavior — David Flanagan <david@...> 2008/03/26

Dave Thomas wrote:

Re: [PATCH] timeouts for ConditionVariable#wait

From: MenTaLguY <mental@...>
Date: 2008-03-11 03:56:03 UTC
List: ruby-core #15852
On Tue, 2008-03-11 at 10:56 +0900, Nobuyoshi Nakada wrote:
> Mutex#sleep is not guaranteed that it exits in the specified
> time, it just sleeps the time with unlocking, and tries to
> achieve the lock again.  If another thread takes the lock at
> that time, it sleeps forever.
>=20
>   $ ruby19 -e '
>   m=3DMutex.new
>   Thread.start{sleep(1); m.synchronize{sleep(10)}}
>   m.synchronize{p m.sleep(2)}'
>   11
>=20
> So I don't think your implementation is very intuitive or
> intented.

It is correct and intended.

In order to preserve correct semantics for condition variables, wait
*MUST* re-acquire the mutex before it returns, and therefore it may have
to compete with other threads in order to do so.  This is the case with
essentially all modern condition variable implementations, including
pthread_cond_timedwait() in POSIX and Object.wait in Java.  This is also
likely the reason that Mutex#sleep was written the way it was, since it
is used as the basis for Ruby 1.9 condition variables.

In real-world practice, the results of this behavior are not especially
counter-intuitive, since condition variables are used in ways which tend
to remove the need to hold their mutex for long periods of time.

> Timeout.timeout works properly in such case.

No it doesn't, for two reasons:

 1. it evidently does not guarantee that the mutex will be correctly
re-acquired upon timeout (if it did, it would display the same behavior
as my wait timeout implementation)

 2. the delivery of an exception injected via Thread.raise is
uncontrolled, potentially leaving the wait list or user data structures
in an inconsistent state

-mental

Attachments (1)

signature.asc (189 Bytes, application/pgp-signature)

In This Thread