<html><head></head><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, Sans-Serif;font-size:14px"><div id="yui_3_16_0_1_1453923143215_4180">Hi ,</div><div id="yui_3_16_0_1_1453923143215_4180"><br></div><div id="yui_3_16_0_1_1453923143215_4180">I am writing my applications based on the examples that come with the Master installation.</div><div id="yui_3_16_0_1_1453923143215_4180"><br></div><div id="yui_3_16_0_1_1453923143215_4180" dir="ltr">The cyclic_task() is executed every time on reception of a timer signal by calling the pause() blocking function. This works if using just one thread.</div><div id="yui_3_16_0_1_1453923143215_4180"><br></div><div id="yui_3_16_0_1_1453923143215_4180">When using multi-threading, such that the function which calls the cyclic_task() is running in a separate detached thread from the main thread, the pause function blocks forever and a signal is never received as below. </div><div id="yui_3_16_0_1_1453923143215_4180"><br></div><div id="yui_3_16_0_1_1453923143215_4180">Does anyone have a solution for this ?</div><div id="yui_3_16_0_1_1453923143215_4180"><br></div><div id="yui_3_16_0_1_1453923143215_4180">Also, I tried to use usleep() and sleep() instead of signals to wait for the right time to call the cyclic_task(), but the timing is not right. It seems that the sleeps can not wait longer than 10ms.</div><div id="yui_3_16_0_1_1453923143215_4180"><br></div><div id="yui_3_16_0_1_1453923143215_4180">Thanks in advance for any help.</div><div id="yui_3_16_0_1_1453923143215_4180"><br></div><div id="yui_3_16_0_1_1453923143215_4180"><br></div><div id="yui_3_16_0_1_1453923143215_4180" class="">/****************************************************************************/</div><div id="yui_3_16_0_1_1453923143215_4180" class=""><br id="yui_3_16_0_1_1453923143215_4663" class=""></div><div id="yui_3_16_0_1_1453923143215_4180" class="">void signal_handler(int signum)</div><div id="yui_3_16_0_1_1453923143215_4180" class="">{</div><div id="yui_3_16_0_1_1453923143215_4180" class=""> switch (signum)</div><div id="yui_3_16_0_1_1453923143215_4180" class=""> {</div><div id="yui_3_16_0_1_1453923143215_4180" class=""> case SIGALRM:</div><div id="yui_3_16_0_1_1453923143215_4180" class=""> sig_alarms++;</div><div id="yui_3_16_0_1_1453923143215_4180" class=""> break;</div><div id="yui_3_16_0_1_1453923143215_4180" class=""> }</div><div id="yui_3_16_0_1_1453923143215_4180" class="">}</div><div id="yui_3_16_0_1_1453923143215_4180" class=""><br id="yui_3_16_0_1_1453923143215_4675" class=""></div><div id="yui_3_16_0_1_1453923143215_4180" dir="ltr" class="">/****************************************************************************/</div><div id="yui_3_16_0_1_1453923143215_4180" class="">///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////</div><div id="yui_3_16_0_1_1453923143215_4180" class="">//This function is assigned to a std::thread and detached</div><div id="yui_3_16_0_1_1453923143215_4180" class=""><br id="yui_3_16_0_1_1453923143215_4492" class=""></div><div id="yui_3_16_0_1_1453923143215_4180" class="">void Ethercat::threadFunc()</div><div id="yui_3_16_0_1_1453923143215_4180" class="">{</div><div id="yui_3_16_0_1_1453923143215_4180" class=""> struct sigaction sa;</div><div id="yui_3_16_0_1_1453923143215_4180" class=""> struct itimerval tv;</div><div id="yui_3_16_0_1_1453923143215_4180" class=""><br id="yui_3_16_0_1_1453923143215_4499" class=""></div><div id="yui_3_16_0_1_1453923143215_4180" class=""> sa.sa_handler = signal_handler;</div><div id="yui_3_16_0_1_1453923143215_4180" class=""> sigemptyset(&sa.sa_mask);</div><div id="yui_3_16_0_1_1453923143215_4180" class=""> sa.sa_flags = 0;</div><div id="yui_3_16_0_1_1453923143215_4180" class=""> if (sigaction(SIGALRM, &sa, 0))</div><div id="yui_3_16_0_1_1453923143215_4180" class=""> {</div><div id="yui_3_16_0_1_1453923143215_4180" class=""> fprintf(stderr, "Failed to install signal handler!!\n");</div><div id="yui_3_16_0_1_1453923143215_4180" class=""> }</div><div id="yui_3_16_0_1_1453923143215_4180" class=""><br id="yui_3_16_0_1_1453923143215_4509" class=""></div><div id="yui_3_16_0_1_1453923143215_4180" class=""><br id="yui_3_16_0_1_1453923143215_4512" class=""></div><div id="yui_3_16_0_1_1453923143215_4180" class=""> printf("Starting timer...\n");</div><div id="yui_3_16_0_1_1453923143215_4180" class=""> tv.it_interval.tv_sec = 0;</div><div id="yui_3_16_0_1_1453923143215_4180" class=""> tv.it_interval.tv_usec = 1000000 / (FREQUENCY * 10);</div><div id="yui_3_16_0_1_1453923143215_4180" class=""> tv.it_value.tv_sec = 0;</div><div id="yui_3_16_0_1_1453923143215_4180" class=""> tv.it_value.tv_usec = 1000000 / ( FREQUENCY * 10);</div><div id="yui_3_16_0_1_1453923143215_4180" class=""> if (setitimer(ITIMER_REAL, &tv, NULL))</div><div id="yui_3_16_0_1_1453923143215_4180" class=""> {</div><div id="yui_3_16_0_1_1453923143215_4180" class=""> fprintf(stderr, "Failed to start timer: %s\n", strerror(errno));</div><div id="yui_3_16_0_1_1453923143215_4180" class=""> }</div><div id="yui_3_16_0_1_1453923143215_4180" class=""><br id="yui_3_16_0_1_1453923143215_4524" class=""></div><div id="yui_3_16_0_1_1453923143215_4180" class=""><br id="yui_3_16_0_1_1453923143215_4527" class=""></div><div id="yui_3_16_0_1_1453923143215_4180" class=""><br id="yui_3_16_0_1_1453923143215_4530" class=""></div><div id="yui_3_16_0_1_1453923143215_4180" class=""> printf("Starting cyclical task.\n");</div><div id="yui_3_16_0_1_1453923143215_4180" class=""><br id="yui_3_16_0_1_1453923143215_4534" class=""></div><div id="yui_3_16_0_1_1453923143215_4180" class=""> while (1)</div><div id="yui_3_16_0_1_1453923143215_4180" class=""> {</div><div id="yui_3_16_0_1_1453923143215_4180" class=""><br id="yui_3_16_0_1_1453923143215_4539" class=""></div><div id="yui_3_16_0_1_1453923143215_4180" class="">#if 0</div><div id="yui_3_16_0_1_1453923143215_4180" class=""> struct timeval t;</div><div id="yui_3_16_0_1_1453923143215_4180" class=""> gettimeofday(&t, NULL);</div><div id="yui_3_16_0_1_1453923143215_4180" class=""> printf("%u.%06u\n", t.tv_sec, t.tv_usec);</div><div id="yui_3_16_0_1_1453923143215_4180" class="">#endif</div><div id="yui_3_16_0_1_1453923143215_4180" class=""> pause();</div><div id="yui_3_16_0_1_1453923143215_4180" class=""> while (sig_alarms != user_alarms)</div><div id="yui_3_16_0_1_1453923143215_4180" class=""> {</div><div id="yui_3_16_0_1_1453923143215_4180" class=""> cyclic_task();</div><div id="yui_3_16_0_1_1453923143215_4180" class=""> user_alarms++;</div><div id="yui_3_16_0_1_1453923143215_4180" class=""> }</div><div id="yui_3_16_0_1_1453923143215_4180" class=""><br id="yui_3_16_0_1_1453923143215_4553" class=""></div><div id="yui_3_16_0_1_1453923143215_4180" class=""> </div><div id="yui_3_16_0_1_1453923143215_4180" class=""> }</div><div id="yui_3_16_0_1_1453923143215_4180" class=""><br></div><div id="yui_3_16_0_1_1453923143215_4180" dir="ltr" class="">}</div><div id="yui_3_16_0_1_1453923143215_4180" dir="ltr" class=""><br></div><div id="yui_3_16_0_1_1453923143215_4180" dir="ltr" class="">/****************************************************************************/<br></div><div id="yui_3_16_0_1_1453923143215_4180" dir="ltr" class=""><br></div><div id="yui_3_16_0_1_1453923143215_4180" dir="ltr" class="">/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////</div></div></body></html>