From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6571 invoked by alias); 19 Nov 2014 15:08:25 -0000 Mailing-List: contact ecos-discuss-help@ecos.sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: ecos-discuss-owner@ecos.sourceware.org Received: (qmail 6557 invoked by uid 89); 19 Nov 2014 15:08:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=3.2 required=5.0 tests=AWL,BAYES_05,LIKELY_SPAM_SUBJECT autolearn=no version=3.3.2 X-HELO: mail1.lodam.dk Received: from mail1.lodam.dk (HELO mail1.lodam.dk) (178.132.236.35) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Wed, 19 Nov 2014 15:08:17 +0000 Received: from EXCH1SRV.lodam.local ([fe80::78ee:20de:fc0b:12a0]) by exch1srv.lodam.local ([fe80::78ee:20de:fc0b:12a0%13]) with mapi id 14.03.0123.003; Wed, 19 Nov 2014 16:08:13 +0100 From: Hans Peter Jepsen To: 'eCos Discussion' Date: Wed, 19 Nov 2014 15:08:00 -0000 Message-ID: <8BA14503034EAE47B93AE568C5A9B47097CF330F@exch1srv.lodam.local> Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: [ECOS] FW: Very serious problem with Cyg_Mutex::trylock(), when eCos is built with CYGDBG_USE_ASSERTS X-SW-Source: 2014-11/txt/msg00003.txt.bz2 Hi After a few days of serious debugging, we think, that we have found, that e= Cos has a very serious problem with Cyg_Mutex::trylock(), when eCos is buil= t 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" an= d "owner". See code below (from file packages/kernel/.../src/sync/mutex.cxx= ). However, since this consistency check is not atomic, is must only be don= e, 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 =3D=3D NULL ) return false; switch( zeal ) { case cyg_system_test: case cyg_extreme: case cyg_thorough: case cyg_quick: case cyg_trivial: if( locked && owner =3D=3D NULL ) return false; if( !locked && owner !=3D NULL ) return false; case cyg_none: default: break; }; return true; } #endif This checking is used in the macro call CYG_ASSERTCLASS( this, "Bad this po= inter") . In Cyg_Mutex::trylock() the checking is done, before launching Cyg_Schedule= r::lock() : cyg_bool Cyg_Mutex::trylock(void) { CYG_REPORT_FUNCTYPE("returning %d"); cyg_bool result =3D 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_Schedul= er::lock() and CYG_ASSERTCLASS( this, "Bad this pointer") in our eyes are c= orrect: cyg_bool Cyg_Mutex::lock(void) { CYG_REPORT_FUNCTYPE("returning %d"); cyg_bool result =3D true; Cyg_Thread *self =3D Cyg_Thread::self(); // Prevent preemption Cyg_Scheduler::lock(); CYG_ASSERTCLASS( this, "Bad this pointer"); Kind regards Hans Peter Jepsen Lodam Electronics, S=F8nderborg, 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