This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Re: [PATCH] Optimized mutex operations
- To: ecos-discuss at sources dot redhat dot com
- Subject: Re: [ECOS] [PATCH] Optimized mutex operations
- From: Robin Farine <acnrf at dial dot eunet dot ch>
- Date: 24 Oct 2001 09:07:00 +0200
- References: <3CB66238087B324A9222A966EACA50EA04C4DA@mail>
"Luoqi Chen" <lchen@onetta.com> writes:
> I've modified the current mutex implementation to take advantage of
> atomic update
> primitives provided in many processors, this should significantly
> improve the
> performance of operations on uncontested mutexi. The patch is available
> at
> http://www.freebsd.org/~luoqi/ecos .
>
> I've also discovered a race in the current mutex implementation's
> priority
> inheritance code: during unlock, the first thread blocking on the sleep
> queue
> is waken and inherits the priority of the previous owner. There lies a
> window
> between unlock returns and the new owner-to-be gets a chance to run in
> which
> another thread blocking on the same mutex might inherit a even higher
> priority,
> and when the owner-to-be becomes the owner, it has a lower priority than
> one
> of the threads blocked.
>
> -lq
I see at least two problems with this implementation (but maybe I'm still
sleeping so ...)
1. lock_inner() works like a spin-lock, not like a mutex. When a thread tries to
acquire an already owned mutex, the thread that owns the mutex will not run
until the next time-slice, thus the thread that polls the lock will keep the
CPU, but uselessly.
2. volatile cyg_atomic locked; // owner and want flag bit
cyg_atomic does not necessarily has the same memory layout as a pointer
Hope this makes sense,
Robin