<?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>Mutex not unlock ?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/95272/mutex-not-unlock</link><description>Hi to all, 
 it&amp;#39;s definitely a trivial thing but I can&amp;#39;t get out of it. Why don&amp;#39;t I unlock the mutex and run the first thread? 
 Thank you.</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 02 Jan 2023 14:44:02 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/95272/mutex-not-unlock" /><item><title>RE: Mutex not unlock ?</title><link>https://devzone.nordicsemi.com/thread/402844?ContentTypeID=1</link><pubDate>Mon, 02 Jan 2023 14:44:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9f1d6951-5b94-4721-b157-22f469806533</guid><dc:creator>babos</dc:creator><description>&lt;p&gt;Hi, Andreas.&lt;/p&gt;
&lt;p&gt;Yes, it is clear and useful, thanks we can close the ticket.&amp;nbsp;I understand.&lt;/p&gt;
&lt;p&gt;best regards&lt;/p&gt;
&lt;p&gt;B.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Mutex not unlock ?</title><link>https://devzone.nordicsemi.com/thread/402819?ContentTypeID=1</link><pubDate>Mon, 02 Jan 2023 13:24:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b6e19465-243d-4db8-b289-8d73ecd2c9dc</guid><dc:creator>AHaug</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;You might&amp;#39;ve already seen this course, but I would recommend you to take a look at the fundamentals course we have at&amp;nbsp;&lt;a href="https://academy.nordicsemi.com/courses/nrf-connect-sdk-fundamentals/"&gt;https://academy.nordicsemi.com/courses/nrf-connect-sdk-fundamentals/&lt;/a&gt;.&amp;nbsp;Topic 7 and topic 8 contains theory and hands on exercises (with solutions) about multithreaded applications and Thread synchronization. Topic 8, exercise 2 (with the &lt;a href="https://github.com/NordicDeveloperAcademy/nRF-Connect-SDK-Fundamentals/blob/main/v2.x.x/lesson8/fund_less8_exer2_solution/src/main.c"&gt;solution&lt;/a&gt;&amp;nbsp;here) even illustrates how to use mutexes to synchronize two threads that attempts to access the same code simultaneously.&lt;/p&gt;
&lt;p&gt;The mentioned topics should give you a hint as for why your implementation might not behave as you expected. As far as I can see the first thread is run once at the beginning, but never again after line 24.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Let me know if the link is helpful and if you have more questions regarding this topic.&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;br /&gt;Andreas&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Mutex not unlock ?</title><link>https://devzone.nordicsemi.com/thread/402717?ContentTypeID=1</link><pubDate>Sat, 31 Dec 2022 13:45:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:15e09b40-fd33-4b8c-8aff-18d3bac126e6</guid><dc:creator>babos</dc:creator><description>&lt;p&gt;or this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/*
 * Copyright (c) 2012-2014 Wind River Systems, Inc.
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include &amp;lt;zephyr/kernel.h&amp;gt;

#define STACKSIZE (1024)
#define PRIORITY 5

K_MUTEX_DEFINE(m1);
K_MUTEX_DEFINE(m2);

/* work thread 1 */
void ping()
{
	while (true)
	{
		k_mutex_lock(&amp;amp;m1, K_FOREVER);
		printk(&amp;quot;ping\n&amp;quot;);
		k_mutex_unlock(&amp;amp;m2);
		k_busy_wait(100000);
		k_msleep(2000);
	}
}
/* work thread 2 */
void pong()
{
	while (true)
	{
		k_mutex_lock(&amp;amp;m2, K_FOREVER);
		printk(&amp;quot;pong\n&amp;quot;);
		k_mutex_unlock(&amp;amp;m1);
		k_busy_wait(100000);
		k_msleep(2000);
	}
}

void main(void)
{
	printk(&amp;quot;WORK MUTEX on board: %s\n\n&amp;quot;, CONFIG_BOARD);
	k_mutex_lock(&amp;amp;m1, K_FOREVER);
	k_mutex_unlock(&amp;amp;m2);
}

K_THREAD_DEFINE(thread_1_id, STACKSIZE, ping, NULL, NULL, NULL,
				PRIORITY, 0, 500);
K_THREAD_DEFINE(thread_2_id, STACKSIZE, pong, NULL, NULL, NULL,
				PRIORITY, 0, 500);&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>