Note that there are some explanatory texts on larger screens.

plurals
  1. POC Seconds ticking failing when need to process queries?
    primarykey
    data
    text
    <p>We have a code a below where it keep ticking for every second it works perfectly fine. The problem starts when we have //select and insert queries need to be process for each and every second we notice there is at time gaps between 1 to 10 seconds. Thus we practically miss some processing to be done. Any idea how to overcome this? Is it that we need to create a separate thread on each second is it?Thank you.</p> <pre><code>void * reader_thread (void * arg) { while (1) { if (flag) { struct timeval tv; char timeBuf[10],secondBuf1[100],queryBuf1[500],queryBuf2[500]; char buff[20] = {0}; gettimeofday (&amp;tv, NULL); //fprintf (stderr, "[%d.%06d] Flag set to 1 on ", tv.tv_sec, tv.tv_usec); tv.tv_sec -= 5; strftime(buff, 20, "%Y-%m-%d %H:%M:%S", localtime(&amp;tv.tv_sec)); printf("\nTime is %s", buff); //select and insert queries fprintf (stderr, " %s\n", buff); flag = 0; } usleep (100); // will skew the processing but not signal delivery } return NULL; } void callback (int sig) { flag = 1; // this is the only thing the callback does } int main () { timer_t tid = 0; pthread_t thread; struct itimerspec it; char *localServer = "localhost", *remoteServer = "localhost"; char *localUser = "user1", *remoteUser = "user2"; char *localPassword = "****", *remotePassword = "*****"; char *localDatabase = "db1", *remoteDatabase = "db1"; localConn = mysql_init(NULL), remoteConn = mysql_init(NULL); if (!mysql_real_connect(localConn, localServer, localUser, localPassword, localDatabase, 0, NULL, 0)) { fprintf(stderr, "%s\n", mysql_error(localConn)); exit(1); } pthread_create (&amp;thread, NULL, reader_thread, NULL); signal (SIGALRM, callback); it.it_value.tv_sec = 1; it.it_value.tv_nsec = 0; it.it_interval.tv_sec = 1; it.it_interval.tv_nsec = 0; timer_create (CLOCK_REALTIME, NULL, &amp;tid); timer_settime (tid, 0, &amp;it, NULL); while (1) sleep (100); return 0; } </code></pre> <p>Edit codes.</p> <pre><code>sigset_t sigset; sigfillset(&amp;sigset); if (pthread_sigmask( SIG_BLOCK, &amp;sigset, NULL)) { perror("pthread_sigmask"); } pthread_create (&amp;thread, NULL, reader_thread, NULL); //sigset_t sigset; //sigemptyset(&amp;sigset); sigaddset(&amp;sigset, SIGALRM); if (pthread_sigmask( SIG_UNBLOCK, &amp;sigset, NULL)) { perror("pthread_sigmask"); } </code></pre>
    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.
    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