<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>how to use same stack space for multiple threads running at different stages of the app</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/103425/how-to-use-same-stack-space-for-multiple-threads-running-at-different-stages-of-the-app</link><description>hello Nordic 
 i am working with nrf52832 and nrf52840 with ncs v2.3.0 
 i have several thread that i create in the application and some of them work when others don&amp;#39;t. 
 in order to save on RAM (which i am limited in, mostly in the nrf52832) i want to</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 18 Sep 2023 10:54:43 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/103425/how-to-use-same-stack-space-for-multiple-threads-running-at-different-stages-of-the-app" /><item><title>RE: how to use same stack space for multiple threads running at different stages of the app</title><link>https://devzone.nordicsemi.com/thread/446439?ContentTypeID=1</link><pubDate>Mon, 18 Sep 2023 10:54:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c7027a07-f4d3-4d88-a7a6-d205d9ed0867</guid><dc:creator>ziv123</dc:creator><description>&lt;p&gt;hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;thanks, though, this much i have found, as can be seen in my previous message.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;however, i will ask if there is a possibility to use the same thread stack object for more then one thread (which run at the same time) but the stack sam required for the 2 or more thread is still smaller then the stack size of the stack object .. maybe by using an array of stacks like &amp;quot;&lt;span&gt;K_THREAD_STACK_ARRAY_DEFINE&amp;quot; but i also will need one of the threads that works alon to use the size of the complete array.. is that possible ?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;2. there are this commit &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;a id="" href="https://github.com/zephyrproject-rtos/zephyr/issues/26999"&gt;https://github.com/zephyrproject-rtos/zephyr/issues/26999&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;a id="" href="https://github.com/zephyrproject-rtos/zephyr/pull/44727"&gt;https://github.com/zephyrproject-rtos/zephyr/pull/44727&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;a id="" href="https://github.com/zephyrproject-rtos/zephyr/issues/25973"&gt;https://github.com/zephyrproject-rtos/zephyr/issues/25973&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;that maybe i did not get it right but it looks like there is some option to&amp;nbsp;create a thread dynamically (using &amp;quot;pthread_create&amp;quot;) with a stack pointer of void type (which can by allocated dynamically i assume)...&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;can you help me understand that better, and how to use it or if there is some example in nrf connect sdk or zephyr that implement such functionality ?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;hope to read you soon&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;best regards&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Ziv&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to use same stack space for multiple threads running at different stages of the app</title><link>https://devzone.nordicsemi.com/thread/446270?ContentTypeID=1</link><pubDate>Fri, 15 Sep 2023 12:26:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8b6752ec-5130-46f9-8ffe-9450f231f845</guid><dc:creator>&amp;#216;ivind</dc:creator><description>&lt;p&gt;Hi again,&lt;/p&gt;
&lt;p&gt;From what I have found, allocating the stack dynamically is not possible, and the closest you would come is to terminate the earlier thread and re-use the stack object for the new thread. &lt;br /&gt;But in that case you might as well use a single thread that handles everything, which you suspend when it is not in use.&lt;/p&gt;
&lt;p&gt;Unfortunately, if that requires too much ram, you may have to look into ways of reducing the peak ram usage of the threads.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to use same stack space for multiple threads running at different stages of the app</title><link>https://devzone.nordicsemi.com/thread/444579?ContentTypeID=1</link><pubDate>Tue, 05 Sep 2023 19:07:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b44b0c9d-4ca8-49f7-84fa-6e75c617ffc7</guid><dc:creator>ziv123</dc:creator><description>&lt;p&gt;just adding i&amp;nbsp;found that it may be possible to define&amp;nbsp;a thread stack with K_THREAD_STACK_DEFINE and then using the defined stack with K_THREAD_STACK_DECLARE for different threads, but since not all thread need the same stack size its not that helpful,&lt;/p&gt;
&lt;p&gt;so to be more specific i hope there is a way, and this is what i haven&amp;#39;t found yet and need help with, to allocate stack for a thread dynamically ..&amp;nbsp;&lt;/p&gt;
&lt;p&gt;hope to read from you soon and hope you will have good findings&amp;nbsp;&lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f60a.svg" title="Blush"&gt;&amp;#x1f60a;&lt;/span&gt;&amp;nbsp;&lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f64f.svg" title="Pray"&gt;&amp;#x1f64f;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to use same stack space for multiple threads running at different stages of the app</title><link>https://devzone.nordicsemi.com/thread/444383?ContentTypeID=1</link><pubDate>Mon, 04 Sep 2023 22:05:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0f3cdbc5-18f0-48f9-92b3-041de23c135e</guid><dc:creator>&amp;#216;ivind</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I&amp;#39;ll look into this and get back to you.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>