#2170 closed defect (fixed)

pthread_mutex_trylock() erroneously returns EDEADLK

Reported by: Nick Withers Owned by: Joel Sherrill
Priority: normal Milestone: 4.11
Component: score Version: 4.11
Severity: normal Keywords:
Cc: Blocked By:
Blocking:

Description (last modified by Gedare Bloom)

By The Open Group Base Specifications Issue 6, pthread_mutex_trylock() should return EBUSY if the lock is already held ( http://pubs.opengroup.org/onlinepubs/009695399/functions/pthread_mutex_lock.html ).

On RTEMS 4.11, it instead returns EDEADLK

Attachments (1)

0001-posix-fix-error-return-code-for-pthread_mutex_tryloc.patch (1.5 KB) - added by Gedare Bloom on Feb 25, 2015 at 7:59:33 PM.
Fix with doc change.

Download all attachments as: .zip

Change History (11)

comment:1 Changed on Feb 5, 2014 at 12:38:59 AM by Nick Withers

By The Open Group Base Specifications Issue 6, pthread_mutex_trylock() should return EBUSY if the lock is already held ( http://pubs.opengroup.org/onlinepubs/009695399/functions/pthread_mutex_lock.html ).

On RTEMS 4.11, it instead returns EDEADLK

comment:2 Changed on Nov 23, 2014 at 4:51:05 PM by Joel Sherrill

Description: modified (diff)

Nick.. can you check mutextranslatereturncode.c and see if it is OK now? I don't seem to be able to match the EDEADLK to the core status I think would match.

comment:3 Changed on Nov 24, 2014 at 1:00:26 AM by Nick Withers

Aha - thanks for the pointer!

cpukit/posix/src/mutextranslatereturncode.c:26:

EDEADLK, /* CORE_MUTEX_STATUS_NESTING_NOT_ALLOWED */

That'll be the one. I've gotta do some running around for the next hour or so, but I'll change that to:

EBUSY, /* CORE_MUTEX_STATUS_NESTING_NOT_ALLOWED */

and see if that sorts it.

comment:4 Changed on Nov 24, 2014 at 1:02:36 AM by Nick Withers

Wait... No, that's not going to work.

pthread_mutex_lock() should return EDEADLK for CORE_MUTEX_STATUS_NESTING_NOT_ALLOWED if the mutex's already locked and pthread_mutex_trylock() should return EBUSY - so they presumably need to return different POSIX codes for the same RTEMS code?

comment:5 Changed on Nov 24, 2014 at 6:58:28 PM by Gedare Bloom

Version: HEAD4.11

Replace Version=HEAD with Version=4.11 for the tickets with Milestone >= 4.11

comment:6 Changed on Feb 24, 2015 at 3:30:32 PM by Gedare Bloom

Description: modified (diff)

The attached patch replaces EDEADLK with EBUSY directly in trylock().

comment:7 Changed on Feb 25, 2015 at 12:31:16 AM by Nick Withers

Works for me - thanks!

(A little embarrassed now though :-P)

comment:8 Changed on Feb 25, 2015 at 12:52:07 AM by Joel Sherrill

Answering on my phone but don't forget this impacts tests and documentation.

Thanks for fixing this Gedare.

Changed on Feb 25, 2015 at 7:59:33 PM by Gedare Bloom

Fix with doc change.

comment:9 Changed on Feb 25, 2015 at 8:01:05 PM by Gedare Bloom <gedare@…>

Resolution: fixed
Status: newclosed

In c0e01a28dad77063d8edb7f7fe2cee83a5f09b2e/rtems:

posix: fix error return code for pthread_mutex_trylock

pthread_mutex_trylock() should return EBUSY if the mutex is already
locked. The translations of CORE_MUTEX_STATUS_NESTING_NOT_ALLOWED is
EDEADLK which is correct for pthread_mutex_lock(). This fixes the
translation for trylock.

Closes #2170.

comment:10 Changed on Feb 26, 2015 at 11:56:25 AM by Sebastian Huber <sebastian.huber@…>

In 6357e14aac7ad9928b81db157d4b0b5506a9d993/rtems:

psxtests/psx05: Adjust test case

Update #2170.

Note: See TracTickets for help on using tickets.