public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
From: Hans Peter Jepsen <hpj@lodam.com>
To: 'eCos Discussion' <ecos-discuss@sourceware.org>
Subject: [ECOS] FW: Very serious problem with Cyg_Mutex::trylock(), when eCos is built with CYGDBG_USE_ASSERTS
Date: Wed, 19 Nov 2014 15:08:00 -0000	[thread overview]
Message-ID: <8BA14503034EAE47B93AE568C5A9B47097CF330F@exch1srv.lodam.local> (raw)

Hi

After a few days of serious debugging, we think, that we have found, that eCos has a very serious problem with Cyg_Mutex::trylock(), when eCos is built with CYGDBG_USE_ASSERTS.

The problem has the impact, that when using cyg_mutex_trylock(), the system might die with an assert failed, although there is no reason for it.

Here is, what we have found:

When build with CYGDBG_USE_ASSERTS the Cyg_Mutex::check_this() method will check, that there is consistency between the instance variables "locked" and "owner". See code below (from file packages/kernel/.../src/sync/mutex.cxx). However, since this consistency check is not atomic, is must only be done, when thread switching is prohibited.

#ifdef CYGDBG_USE_ASSERTS

cyg_bool
Cyg_Mutex::check_this( cyg_assert_class_zeal zeal) const
{
//    CYG_REPORT_FUNCTION();

    // check that we have a non-NULL pointer first
    if( this == NULL ) return false;

    switch( zeal )
    {
    case cyg_system_test:
    case cyg_extreme:
    case cyg_thorough:
    case cyg_quick:
    case cyg_trivial:
        if(  locked && owner == NULL ) return false;
        if( !locked && owner != NULL ) return false;
    case cyg_none:
    default:
        break;
    };

    return true;
}

#endif


This checking is used in the macro call CYG_ASSERTCLASS( this, "Bad this pointer") .
In Cyg_Mutex::trylock() the checking is done, before launching Cyg_Scheduler::lock() :

cyg_bool
Cyg_Mutex::trylock(void)
{
    CYG_REPORT_FUNCTYPE("returning %d");

    cyg_bool result = true;

    CYG_ASSERTCLASS( this, "Bad this pointer");

    // Prevent preemption
    Cyg_Scheduler::lock();


We ended up using Cyg_Mutex::lock() instead, where the order of Cyg_Scheduler::lock() and CYG_ASSERTCLASS( this, "Bad this pointer") in our eyes are correct:

cyg_bool
Cyg_Mutex::lock(void)
{
    CYG_REPORT_FUNCTYPE("returning %d");

    cyg_bool result = true;
    Cyg_Thread *self = Cyg_Thread::self();

    // Prevent preemption
    Cyg_Scheduler::lock();

    CYG_ASSERTCLASS( this, "Bad this pointer");


Kind regards

Hans Peter Jepsen
Lodam Electronics, Sønderborg, Denmark

--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

                 reply	other threads:[~2014-11-19 15:08 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8BA14503034EAE47B93AE568C5A9B47097CF330F@exch1srv.lodam.local \
    --to=hpj@lodam.com \
    --cc=ecos-discuss@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).