Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to run thread in main function infinitely without causing program to terminate
    primarykey
    data
    text
    <p>I have a function say <code>void *WorkerThread ( void *ptr)</code>.</p> <p>The function <code>*WorkerThread( void *ptr)</code> has infinite loop which reads and writes continously from Serial Port</p> <p>example</p> <pre><code>void *WorkerThread( void *ptr) { while(1) { // READS AND WRITE from Serial Port USING MUXTEX_LOCK AND MUTEX_UNLOCK } //while ends } </code></pre> <p>The other function I worte is <code>ThreadTest</code> example </p> <pre><code>int ThreadTest() { pthread_t Worker; int iret1; pthread_mutex_init(&amp;stop_mutex, NULL); if( iret1 = pthread_create(&amp;Worker, NULL, WorkerThread, NULL) == 0) { pthread_mutex_lock(&amp;stop_mutex); stopThread = true; pthread_mutex_unlock(&amp;stop_mutex); } if (stopThread != false) stopThread = false; pthread_mutex_destroy(&amp;stop_mutex); return 0; } </code></pre> <p>In <code>main</code> function<br> I have something like </p> <pre><code>int main(int argc, char **argv) { fd = OpenSerialPort(); if( ConfigurePort(fd) &lt; 0) return 0; while (true) { ThreadTest(); } return 0; } </code></pre> <p>Now, when I run this sort of code with debug statement it runs fine for few hours and then throw message like "can't able to create thread" and application terminates. Does anyone have an idea where I am making mistakes. Also if there is way to run <code>ThreadTest</code> in <code>main</code> with using <code>while(true)</code> as I am already using <code>while(1)</code> in <code>ThreadWorker</code> to read and write infinitely. All comments and criticism are welcome. Thanks &amp; regards, SamPrat.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload