<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7652.24">
<TITLE>Stdout console clogging =&gt; 300ms blocked</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/rtf format -->

<P><FONT SIZE=2 FACE="Arial">System details:</FONT>

<BR><FONT SIZE=2 FACE="Arial">Freescale MPC8347@200MHz</FONT>

<BR><FONT SIZE=2 FACE="Arial">Kernel 2.6.18</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">Problem:</FONT>

<BR><FONT SIZE=2 FACE="Arial">When we log debug output via the serial console on a multithreaded application, the console throughput may get clogged and then we experience a &gt;300ms deadlock.</FONT></P>

<P><FONT SIZE=2 FACE="Arial">Quick and dirty test program: threadtest.c:</FONT>

<BR><FONT SIZE=2 FACE="Arial">//-----------------------------------------------------------------------------------------------</FONT>

<BR><FONT SIZE=2 FACE="Arial">#include &lt;pthread.h&gt;</FONT>

<BR><FONT SIZE=2 FACE="Arial">#include &lt;stdio.h&gt;</FONT>

<BR><FONT SIZE=2 FACE="Arial">#include &lt;sys/time.h&gt;</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">#define THREAD_DELAY 1000</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">void* thread_1(void* unused)</FONT>

<BR><FONT SIZE=2 FACE="Arial">{</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2 FACE="Arial">while (1)</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2 FACE="Arial">{</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2 FACE="Arial">usleep(THREAD_DELAY);</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2 FACE="Arial">fprintf(stdout,&quot; &lt;----- thread 1\n&quot;);</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2 FACE="Arial">}</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2 FACE="Arial">return NULL;</FONT>

<BR><FONT SIZE=2 FACE="Arial">}</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">void* thread_2(void* unused)</FONT>

<BR><FONT SIZE=2 FACE="Arial">{</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2 FACE="Arial">static long ts_old;</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2 FACE="Arial">long ts;</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2 FACE="Arial">struct timeval tv;</FONT>
</P>

<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2 FACE="Arial">while (1)</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2 FACE="Arial">{</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2 FACE="Arial">usleep(THREAD_DELAY);</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2 FACE="Arial">fprintf(stdout,&quot; &lt;----- thread 2\n&quot;);</FONT>
</P>

<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2 FACE="Arial">gettimeofday (&amp;tv, NULL);</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2 FACE="Arial">ts = (tv.tv_sec * 1000L) + (tv.tv_usec / 1000L);</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2 FACE="Arial">if ((ts - ts_old) &gt; 100)</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2 FACE="Arial">{</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2 FACE="Arial">fprintf(stdout, &quot;!!!!!!!!!!! thread2 interval timeout = %d ms\n&quot;,(int)(ts - ts_old));</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2 FACE="Arial">}</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2 FACE="Arial">ts_old = ts;</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2 FACE="Arial">}</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2 FACE="Arial">return NULL;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">}</FONT>
</P>
<BR>
<BR>

<P><FONT SIZE=2 FACE="Arial">int main()</FONT>

<BR><FONT SIZE=2 FACE="Arial">{</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2 FACE="Arial">pthread_t pthread_id_1, pthread_id_2;</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2 FACE="Arial">pthread_create(&amp;pthread_id_1,NULL,&amp;thread_1,NULL);</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2 FACE="Arial">pthread_create(&amp;pthread_id_2,NULL,&amp;thread_2,NULL);</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2 FACE="Arial">while (1)</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2 FACE="Arial">{</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2 FACE="Arial">}</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2 FACE="Arial">return 0;</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">}</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">//-----------------------------------------------------------------------------------------------</FONT>
</P>

<P><FONT SIZE=2 FACE="Courier New">Build command on our platform: </FONT>

<BR><FONT SIZE=2 FACE="Courier New">powerpc-linux-uclibc-gcc threadtest.c&nbsp; -lpthread -o threadtest</FONT>

<BR><FONT SIZE=2 FACE="Courier New">Execute: ./threadtest &gt; /dev/console &amp;</FONT>
</P>

<P><FONT SIZE=2 FACE="Courier New">Uboot settings for the serial console:</FONT>

<BR><FONT SIZE=2 FACE="Courier New">consoledev=ttyS0</FONT>

<BR><FONT SIZE=2 FACE="Courier New">baudrate=115200</FONT>

<BR><FONT SIZE=2 FACE="Courier New">stdin=serial</FONT>

<BR><FONT SIZE=2 FACE="Courier New">stdout=serial</FONT>

<BR><FONT SIZE=2 FACE="Courier New">stderr=serial</FONT>

<BR><FONT SIZE=2 FACE="Courier New">boot_go=setenv bootargs console=$consoledev,$baudrate $args_rtc $args_mtd $args_nfs $args_debug;bootm $addr_kernel $addr_root $addr_dtb</FONT></P>
<BR>

<P><FONT SIZE=2 FACE="Courier New">Expected output [snippet] on the console:</FONT>

<BR><FONT SIZE=2 FACE="Courier New">.... /\ ........</FONT>

<BR><FONT SIZE=2 FACE="Courier New">&nbsp;&lt;----- thread 1</FONT>

<BR><FONT SIZE=2 FACE="Courier New">&nbsp;&lt;----- thread 2</FONT>

<BR><FONT SIZE=2 FACE="Courier New">&nbsp;&lt;----- thread 1</FONT>

<BR><FONT SIZE=2 FACE="Courier New">&nbsp;&lt;----- thread 2</FONT>

<BR><FONT SIZE=2 FACE="Courier New">&nbsp;&lt;----- thread 1</FONT>

<BR><FONT SIZE=2 FACE="Courier New">&nbsp;&lt;----- thread 2</FONT>

<BR><FONT SIZE=2 FACE="Courier New">&nbsp;&lt;----- thread 1</FONT>

<BR><FONT SIZE=2 FACE="Courier New">&nbsp;&lt;----- thread 2</FONT>

<BR><FONT SIZE=2 FACE="Courier New">&nbsp;&lt;----- thread 1</FONT>

<BR><FONT SIZE=2 FACE="Courier New">&nbsp;&lt;----- thread 2</FONT>

<BR><FONT SIZE=2 FACE="Courier New">&nbsp;&lt;----- thread 1</FONT>

<BR><FONT SIZE=2 FACE="Courier New">.... /\ ........</FONT>
</P>

<P><FONT SIZE=2 FACE="Courier New">Real output on the console:</FONT>
</P>

<P><FONT SIZE=2 FACE="Courier New">.... /\ ........</FONT>

<BR><FONT SIZE=2 FACE="Courier New">&nbsp;&lt;----- thread 1</FONT>

<BR><FONT SIZE=2 FACE="Courier New">&nbsp;&lt;----- thread 2</FONT>

<BR><FONT SIZE=2 FACE="Courier New">&nbsp;&lt;----- thread 1</FONT>

<BR><FONT SIZE=2 FACE="Courier New">&nbsp;&lt;----- thread 2</FONT>

<BR><FONT SIZE=2 FACE="Courier New">&nbsp;&lt;----- thread 1</FONT>

<BR><FONT SIZE=2 FACE="Courier New">&nbsp;&lt;----- thread 2</FONT>

<BR><FONT SIZE=2 FACE="Courier New">!!!!!!!!!!! thread2 interval timeout = 335 ms</FONT>

<BR><FONT SIZE=2 FACE="Courier New">&nbsp;&lt;----- thread 1</FONT>

<BR><FONT SIZE=2 FACE="Courier New">&nbsp;&lt;----- thread 2</FONT>

<BR><FONT SIZE=2 FACE="Courier New">&nbsp;&lt;----- thread 1</FONT>

<BR><FONT SIZE=2 FACE="Courier New">&nbsp;&lt;----- thread 2</FONT>

<BR><FONT SIZE=2 FACE="Courier New">&nbsp;&lt;----- thread 1</FONT>

<BR><FONT SIZE=2 FACE="Courier New">.... /\ ........ </FONT>
</P>

<P><FONT SIZE=2 FACE="Courier New">This timeout shows up around every second and has always about the same value of 335 ms.</FONT>

<BR><FONT SIZE=2 FACE="Courier New">Can somebody reproduce this behaviour ( the console speed and/or thread interval may have to be tweaked to clog the serial output) ?</FONT></P>

<P><FONT SIZE=2 FACE="Courier New">Thank you in advance for your help.</FONT>

<BR><FONT SIZE=2 FACE="Courier New">Bernard</FONT>
</P>
<BR>
<BR>
<BR>

<P><B><FONT SIZE=1 FACE="Verdana">-----------------------------------------------------------</FONT></B>

<BR><B><SPAN LANG="fr-be"><FONT SIZE=1 FACE="Verdana">Bernard Willaert<BR>
</FONT></SPAN></B><SPAN LANG="fr-be"></SPAN><SPAN LANG="en-us"><FONT COLOR="#808080" SIZE=1 FACE="Verdana">Software Development Engineer Modality OEM Solutions</FONT></SPAN>

<BR><SPAN LANG="fr-be"><FONT SIZE=1 FACE="Verdana">BARCO Medical Imaging Division<BR>
</FONT><FONT COLOR="#808080" SIZE=1 FACE="Verdana">President Kennedypark 35 - B-8500 KORTRIJK - BELGIUM<BR>
Tel.&nbsp; +32 56 233 439&nbsp; Fax +32 56 233 457<BR>
</FONT></SPAN><A HREF="file://www.barco.com/medical"><SPAN LANG="fr-be"><U></U><U><FONT COLOR="#0000FF" SIZE=1 FACE="Verdana">www.barco.com/medical</FONT></U></SPAN></A><SPAN LANG="fr-be"><BR>
</SPAN><A HREF="mailto:bernard.willaert@barco.com"><SPAN LANG="fr-be"><U></U><U><FONT COLOR="#0000FF" SIZE=1 FACE="Verdana">mailto:bernard.willaert@barco.com</FONT></U></SPAN></A><SPAN LANG="fr-be"></SPAN>
</P>
<BR>
<BR>

<p></p><p>DISCLAIMER:<br>Unless indicated otherwise, the information contained in this message is privileged and confidential, and is intended only for the use of the addressee(s) named above and others who have been specifically authorized to receive it. If you are not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this message and/or attachments is strictly prohibited. The company accepts no liability for any damage caused by any virus transmitted by this email. Furthermore, the company does not warrant a proper and complete transmission of this information, nor does it accept liability for any delays. If you have received this message in error, please contact the sender and delete the message. Thank you.</BODY>
</HTML>