I created a thread from one of my process as below:
if ( ( GetFrame_pid = tfork( GetFrame_Stack,
sizeof( GetFrame_Stack ),
( int ( * )( void * ) )( &GetFrameMain ),
( int *)&socket, 0 ) ) == -1 )
printf( "\nError ...\n" );
And in GetFrameMain() function, i built a loop to get some messages from a list in which another thread would push the messages, codes as below:
void GetFrameMain( void *args )
qnx_scheduler( 0, 0, SCHED_FIFO, getprio( 0 ), 0 );
while( 1 )
if( GetFrame( intChildSocket, &extern_out_buffer ) == 1 )
printf( "### Get Frame Success......\n" );
GetFrame( int, struct ZZ * ) function containts a nother loop like GetFrameMain( void *args ) except that it would break out when messages come.
When GetFrameMain thread was created, later thread would never be performed ( i could not type any characters even ).
I got lost in this. Did i make any mistakes?
Thanks in advance.
Check to make sure all the system calls are thread-safe. QNX4 was never really designed with threading in mind and you may find that you will have to be careful to get it working at all.
There should be a box at the bottom of each call in the helpviewer which says whether the functions are signal/interrupt/thread safe.
Unrelated but SCHED_FIFO is evil, if you rely on this for your design, then your design will break under SMP.
Instead of tfork look at pthread_create.
Without the code of GetFrame() there isn`t much I can say. My guess is you are busy waiting and consuming all the CPU
In QNX4? Did someone port a pthreads lib to it?
I assume he was using QNX because of the qnx_scheduler() call.
Ok yeah I missed the qnx_scheduler, hence my comment about SCHED_FIFO doesn
t apply. QNX4 doesnt support SMP
That being said, yes Rick there is a pthread library for QNX4. Was written by a QNX staffer, but never officially supported, obviously.
About the code, although the docs thats about using SCHED_FIFO to allow for some safety, it`s NOT a guaranty at all. I see in your code that you are using socket, TCP/IP is NOT thread safe. REally need to see the code on this one.
Unless you really really really have to, stay away from threads under QNX4.
Yes i am using QNX4 and socket, TCP/IP.
When i got rid of the loop in GetFrame() function( So, there was only one loop in GetFrameMain thread ), all were OK. But socket would be broken sometimes and GetFrameMain thread would be broken later.
What did happen to socket? And what can i do for this? Process? Or any other protections?
I think the answer is don’t use threads. Unless you are porting code, there is no reason to use threads to do anything in QNX4. There are some situation which are better solved by threads, but the workaround is a better solution given the issues with trying to thread in QNX 4.