My first self-tutoring project in QNX 6.2.1 (Pro. eval. edition) is to
start a thread that generates a random number for display every N seconds.
The creation of the thread is a function associated to a “Init” button in
a window built under PhAB. Whether the new number is actually updated is
governed by a flag that is set or reset by another pair of
PhAB-constructed buttons.
The problem is that the thread seems to only execute once and the window
closes when a sleep(N) function is invoked for the planned delay. When
sleep(N)is commented out then the thread hammers the output area
continuously until I slay the whole task.
The thread for display widget “text_out”:
void* timed_data(void* arg) {
//omit some declarations…
do {
if (running) {
sprintf( buf, “%d”, rand() ) ;
PtSetResource( ABW_text_out, Pt_ARG_TEXT_STRING,
buf, 0) ;
}
sleep( 2 ) ; // or delay(2000);
} while ( 1 ) ;
The initiation function tied to button “init”:
int init_time_data( /usual args/ ) {
pthread_attr_t data_attr ;
pthread_attr_init( &data_attr ) ;
pthread_attr_setdetachedstate( &data_attr,
PTHREAD_CREATE_DETACHED );
pthread_create( NULL, &data_attr, &timed_data, NULL ) ;
return Pt_CONTINUE ;
}
Why doesn’t timed_data() run continuously with a 2-second pause between
widget updates?
Thanks for reading this far!
Bob