[En-Nut-Discussion] Can a thread determine its stack space?

Henrik Maier hmnews at proconx.com
Thu Sep 23 01:51:54 CEST 2010

Hi Ulrich,

If you enable just NUTDEBUG_CHECK_STACK during system build,
NutThreadStackAvailable() tells you how much unused stack is available for a
given thread.

This is done using a pattern check for the DEADBEEF pattern. This has no
other performance or code impact to a system than that the stack is filled
with a pattern upon creation in NutThreadCreate().

Refer to context.c and thread.c source code.


> -----Original Message-----
> From: en-nut-discussion-bounces at egnite.de [mailto:en-nut-discussion-
> bounces at egnite.de] On Behalf Of Ulrich Prinz
> Sent: Thursday, 23 September 2010 6:13 AM
> To: Ethernut User Chat (English)
> Subject: [En-Nut-Discussion] Can a thread determine its stack space?
> Hi!
> Can a stack determine its own stack space? I.e. I want a thread to
> monitor its own left free stack space. But I cannot find out how to do
> that.
> There are functions that are only available if some debug settings are
> enabled. And some of them are never available as the #defines are never
> set and not available through nutconf.
> But enabling heap debugging doesn't solve the problem if a thread
> silently hangs up while the rest of the system is still running fine.
> And the output of NutHeapAvailable() and NutHeapRootRegionAvailable()
> in the main thread still show plenty of memory.
> Is there a mechanism to find a mutex where a thread is blocked on?
> Enabling debugging has another problem too as it multiplies some stacks
> for init and main and others with a factor what has a general impact on
> the system. So it is difficult to find the problem in a surrounding
> that
> is different from what you target on.
> This might also get difficult if your application needs most of FLASH
> and RAM.
> Best regards
> Ulrich
> _______________________________________________
> http://lists.egnite.de/mailman/listinfo/en-nut-discussion

More information about the En-Nut-Discussion mailing list