Integrate Photon GUI with a multi-thread program

Hi All,

   I am writing a testing program sending data from a non-photon thread to photon thread, the program runs a while and terminates,the result  is printed :

Get convar
condvar1: consumed 28
condvar1: produced 29
Get convar
condvar1: consumed 29
condvar1: produced 30
Get convar
condvar1: consumed 30

   I am wery appreciated for any advice on integrating photon GUI with non-photon multithread programming.

  The program is as below:

pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;

void *consumer (void *);
void *producer (void *);

char *progname = “condvar1”;
void *
producer (void *arg)
{
while (1) {
pthread_mutex_lock (&mutex);
while (condition == 1) {
pthread_cond_wait (&cond, &mutex);
}
printf ("%s: produced %d\n", progname, ++count);
condition = 1;
pthread_cond_signal (&cond);
pthread_mutex_unlock (&mutex);
}
return (NULL);
}

   void *

consumerPh (void *arg)
{

PtInit(NULL);
while (1) {
    
 
 // if( PtEnter( 0 ) < 0 )
 // {
 //    perror( "Failed PtEnter()" );
 //    return( NULL );
 // }
    
    
    while (condition == 0) {
        //pthread_cond_wait (&cond, &mutex);
    	PtCondWait(&cond);
    	
    }
    pthread_mutex_lock (&mutex);
    printf("Get convar\n");
 
    printf ("%s:  consumed %d\n", progname, count);
    condition = 0;
    pthread_cond_signal (&cond);
    pthread_mutex_unlock (&mutex);

	/*
   * cleanup 
   */
 /*
  if( PtLeave( 0 ) < 0 )
  {
     perror( "Failed PtLeave()" );
     printf( "You'll have to slay this process to kill it\n" );
     return( NULL );
  }
  */
}
return (NULL);

}

int
main ( int argc, char *argv[] )

{

_Ap_.Ap_winstate = 0;

//condvar
condition = 0;
            count = 0;

            pthread_create (NULL, NULL, consumerPh, NULL);
            pthread_create (NULL, NULL, producer, NULL);
////////////////////////////////////////////////////////////

/* AppBuilder Initialization */
ApInitialize( argc, argv, &AbContext );

/* Display main window */
ApLinkWindow( NULL, &AbApplLinks[0], NULL );

/* Loop until user quits application */
PtMainLoop( );
PtExit( 0 );

return 0;
} 

Rgds,
Shilunz