Sounds like you’re talking about QNX4, and this newsgroup is specific to QNX6.
You may get a better response by posting in qdn.public.qnx4, although more
likely than not someone will also be able to help you here.
If I recall, threads are not native to QNX4, and there are a number of caveats
involved in their use (although it is possible). My suggestion would be to go
with a single-threaded design if you are indeed using QNX4, or switch to QNX6
if you really want multi-threading. Here is a sample that might help you:
pid_t Tproxy;
timer_t Timer;
void init_timer( void )
{
struct itimerspec ts;
struct sigevent event;
/*
** Attach a proxy for the timer to trigger
*/
if( ( Tproxy = qnx_proxy_attach( 0, 0, 0, -1 ) ) == -1 )
fatal( “error %d attaching timer proxy”, errno );
/*
** Fill in a sigevent structure with the proxy ID, create the timer
*/
memset( &event, 0, sizeof( event ) );
event.sigev_signo = -Tproxy;
if( ( Timer = timer_create( CLOCK_REALTIME, &event ) ) == -1 )
fatal( “error %d creating timer”, errno );
/*
** Set the initial and interval values for the timer
*/
memset( &ts, 0, sizeof( ts ) );
ts.it_value.tv_sec = SECONDS;
ts.it_value.tv_nsec = NANOSECS;
ts.it_interval.tv_sec = SECONDS;
ts.it_interval.tv_nsec = NANOSECS;
if( timer_settime( Timer, 0, &ts, NULL ) == -1 )
fatal( “error %d setting timer value”, errno );
}
void timer_proxy( void )
{
/*
** Handle a timer “tick” here
*/
}
void main( void )
{
init_timer( );
/*
** Main loop
*/
for( ; ; )
{
my_msg_t msg;
pid_t pid;
/*
** Receive a message
*/
memset( &msg, 0, MY_MSGSZ );
if( ( pid = Receive( 0, &msg, MY_MSGSZ ) ) == -1 )
continue;
/*
** Check for a timer proxy
*/
if( pid == Tproxy )
{
timer_proxy( );
continue;
}
/*
** Process message here
*/
/* And so on */
}
}
“Fred Schreiber” <fschreiber@emsdevelopment.com> wrote in message
news:3A3F8B64.3CA50A71@emsdevelopment.com…
| Hello QNX World,
| I’ve just started using QNX, to write a pretty plain-jane real-time
| app. After all the promises of gobs of support coming out of the
| woodwork, my sales rep has gone silent; the recommended thrird party
| (CBT) training outfit won’t return emails, and my friendly, highly
| knowledgeable “peers” (in a sister division) have also vanished into a
| black hole. I find myself stuck in first gear.
| Question 1) _beginthread and _endthread: Like a good beginner I
| followed the example in the on-line “Help” for _beginthread, and even
| got it to compile. But the linker can’t find these two functions in the
| libraries. The only LIBPATH I know of is /usr/lib. Is there another
| one lurking?
|
| Q2) timer_create and timer_settime: I’d really like to be able to start
| a RUNNING timer, at a nice fixed frequency. For my first shot I’d be
| happy with 1 Hz, then I’ll delve into nanoseconds later. Whether I use
| the friendly Help sample (which sets up a simple proxy) or swipe some
| code from an older project using signals, all I can get is the first
| “tick” to go off (defined in the .it_value fields). The program then
| politely exits, regardless of the (non-zero!!) values in the
| .it_interval fields.
|
| Can anyone get me to square 2?
|
|
Fred Schreiber |
Software Engineering Manager |
EMS Development Corp. |
(631) 345-6200 x321 |
|
|