From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26184 invoked by alias); 1 Nov 2013 17:04:14 -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 26170 invoked by uid 89); 1 Nov 2013 17:04:13 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.6 required=5.0 tests=AWL,BAYES_50,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 X-HELO: calivar.com Received: from calivar.demon.co.uk (HELO calivar.com) (83.104.54.243) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Fri, 01 Nov 2013 17:04:12 +0000 Received: from daikon.calivar.com (daikon.calivar.com [10.0.1.1]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by calivar.com (Postfix) with ESMTPS id 5B85C5FEFD; Fri, 1 Nov 2013 17:04:08 +0000 (GMT) Message-ID: <5273DF08.2000708@calivar.com> Date: Fri, 01 Nov 2013 17:04:00 -0000 From: Nick Garnett User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.0 MIME-Version: 1.0 To: Grant Edwards , ecos-discuss@ecos.sourceware.org References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Subject: Re: [ECOS] How to know if scheduler has started? X-SW-Source: 2013-11/txt/msg00002.txt.bz2 On 31/10/13 16:24, Grant Edwards wrote: > This question has come up many times in the past 10-12 years, but I've > never seen a real answer: > > How do you tell if the scheduler has been started? > > Specifically, how do you know when it's safe to attempt to lock a mutex? > > Several people have suggested this snippet: > > scheduler_running = cyg_thread_self() != cyg_thread_idle_thread(); > > That seems to work when called from cyg_user_start() and from normal > threads, but it doesn't work when called from initialization code in > a device driver. > > So, I'll ask again: > > how does one write code that knows to lock/unlock a mutex when called > from a normal user thread but not attempt the lock/unlock whcn called > from initialization code in cyg_user_start() or a device driver? > > The function does not get called from ISR/DSR contexts: it is only > called during initialization (before the scheduler is started) and > from normal user threads. > > OTOH, are you are allowed to lock/unlock mutexes from initialization > code? Maybe I'm misremembering, but I thought that was forbidden? > You are allowed to lock/unlock a mutex during initialization. That is why the idle thread is set current throughout the init code, and why the trick you mention above will work. Obviously you need to avoid anything that might cause a thread to sleep, and to leave any mutexes unlocked when you return. -- Nick Garnett Kernel Architect eCosCentric Limited http://www.eCosCentric.com The eCos experts Barnwell House, Barnwell Drive, Cambridge, UK. Tel: +44 1223 245571 Registered in England and Wales: Reg No: 4422071 -- Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss