public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
From: Nick Garnett <nickg@calivar.com>
To: Grant Edwards <grant.b.edwards@gmail.com>,
	 ecos-discuss@ecos.sourceware.org
Subject: Re: [ECOS] How to know if scheduler has started?
Date: Fri, 01 Nov 2013 17:04:00 -0000	[thread overview]
Message-ID: <5273DF08.2000708@calivar.com> (raw)
In-Reply-To: <l4u08n$cap$1@ger.gmane.org>



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

  reply	other threads:[~2013-11-01 17:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-31 16:25 Grant Edwards
2013-11-01 17:04 ` Nick Garnett [this message]
2013-11-02 16:26   ` [ECOS] " Grant Edwards
  -- strict thread matches above, loose matches on Subject: below --
2003-09-17 14:49 [ECOS] " Grant Edwards

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=5273DF08.2000708@calivar.com \
    --to=nickg@calivar.com \
    --cc=ecos-discuss@ecos.sourceware.org \
    --cc=grant.b.edwards@gmail.com \
    /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).