#include #include #ifdef SUN #include #endif #include #include #include #include #include #include // read(), write(), close() #include // thread // #include // thread #include #include "tcp.h" #include "tcpstream.h" //----------- S H A R E D _ M E M O R Y ------------------- #include "sparse_mask.h" // must be included for GLOBAL_VAR.h #include "../client/sparse_2.h" // must be included for GLOBAL_VAR.h #include "../manage/manage.h" // must be included before GLOB #include "GLOBAL_VARIABLE.h" void client_network ( tcp_Stream * ); // file client.c void *display_thread ( void * ); // display.c void *manage_thread ( void * ); main(int argc, char ** argv) { int port_number =1222; char * servername = "brutus.ams.sunysb.edu" ; if (argc >=2 ) servername = argv[1]; if (argc ==3 ) port_number = atoi ( argv[2] ); int sd = open_socket ( servername, servername , port_number ); cout << "the socket is " << sd << endl; tcp_Stream netstream ( sd ); //------------ initialise semaphore ------------------// sem_init ( &DATA_READY ,1, 1 ); //----- between D I S P L A Y and S U B _ D I S P L A Y sem_init ( &SUB_DISPLAY_SYNC ,1, 0 ); //----- betwenn M A N A G E R <--------> D I S P L A Y sem_init ( &D_IS_EMPTY ,1, 1 ); sem_init ( &D_IS_FULL ,1, 0 ); sem_init ( &D_DATA_LOCK ,1, 1 ); sem_init ( &D_JOB_DONE ,1, 0 ); //----- betwenn M A N A G E R <--------> N E T W O R K sem_init ( &N_IS_EMPTY ,1, 1 ); sem_init ( &N_IS_FULL ,1, 0 ); sem_init ( &N_DATA_LOCK ,1, 1 ); sem_init ( &N_JOB_DONE ,1, 0 ); //----- betwenn M A N A G E R <--------> I N P U T sem_init ( &I_IS_EMPTY ,1, 1 ); sem_init ( &I_IS_FULL ,1, 0 ); sem_init ( &I_DATA_LOCK ,1, 1 ); //----- the sum of N_IS_EMPTY, D_IS_EMPTY and I_FULL ---- sem_init ( &D_EMPTY_N_EMPTY_I_FULL ,1, 2 ); //------------ start the //------------ D I S P L A Y t h r e a d. pthread_t display_id; pthread_create ( &display_id, NULL, display_thread, NULL ); //------------ start the //------------ M A N A G E t h r e a d. pthread_t manager_id; pthread_create ( &manager_id, NULL, manage_thread, NULL ); //------------ the main thread will continue to be the //------------ N E T W O R K t h r e a d. client_network ( &netstream ); //------------ q u i t pthread_kill ( display_id, SIGKILL); pthread_join ( display_id, NULL ); }