Re: Interval timers on Fedora



Douglas Phillipson wrote:


[snip]

My result on the timer issue is that a interval timer won't call its timeout function while msgrcv() is waiting for a message on a queue.

Regards

Doug P


Strange, it works for me. Try this!

Regards,

John


#include <stdio.h>
#include <stdlib.h>
#include <sys/ipc.h>
#include <signal.h>
#include <errno.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>

static int signal_cnt;

//--------------------------------------------------------------------------------

void catch_signal ( int ignored )
{
++ signal_cnt;
}

//--------------------------------------------------------------------------------

int main ( int argc, char **argv )
{
// create msg queue

int mqid;

if ( ( mqid = msgget ( (key_t) 12345, IPC_CREAT | 0600 ) ) == -1 )
{
exit ( 1 );
}

// set a timer

struct itimerval it;
struct sigaction sa;

memset ( &sa, 0, sizeof ( sa ) );
sa.sa_handler = catch_signal;
sigemptyset ( &sa.sa_mask );
sa.sa_flags = SA_RESTART;
sigaction ( SIGALRM, &sa, NULL );

memset ( &it, 0, sizeof ( it ) );
it.it_interval.tv_sec = 5;
it.it_value.tv_sec = 5;

if ( setitimer ( ITIMER_REAL, &it, NULL ) )
{
exit ( 1 );
}

struct msgbuf *msgp; ssize_t msz;

msgp = malloc ( 512 );

for ( ;; )
{
// get a message

if ( ( msz = msgrcv ( mqid, msgp, 256, 0, 0 ) ) == -1 )
{
printf ( "msgrcv returned errno [%d]\n", errno );
}

fprintf ( stderr, "signal count [%d]\n", signal_cnt );
}

return 0;
}

--
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list



Relevant Pages

  • Re: Lahman, how ya doing?
    ... Object* recipient; int event_id; ... Timer ... Not relevant to my simulation, but generalizing to a case where any amount of time can pass between when an event is pushed on to the queue and when it is popped off and processed, it seems you can have two identical events going to the same object. ... given tick. ...
    (comp.object)
  • Re: Running two instances of BizTalk generated code?
    ... compoinent names or changes to orchestrations, I MUST find a way to support ... This WAS is configured to talk to a queue manager running on UNIX. ... our INT and QT WAS applications are currently being fed by a single BizTalk ...
    (microsoft.public.biztalk.general)
  • Re: [GIT PULL] block/splice bits for 2.6.29
    ... export SSD/non-rotational queue flag through sysfs ... if (!ret) { ... int el_ret, nr_sectors; ... header-y += bpqether.h ...
    (Linux-Kernel)
  • [GIT PULL] block/splice bits for 2.6.29
    ... export SSD/non-rotational queue flag through sysfs ... int el_ret, nr_sectors; ... * Drop the inode semaphore and wait for a pipe event, ... header-y += bpqether.h ...
    (Linux-Kernel)
  • Re: writing ISR for UART
    ... int putpoint; ... so if the interrupt handler adds a character to the queue while ... detect whether a character is available. ...
    (comp.arch.embedded)