asst1-Synchronization/kern/asst1/client_server_tester.c
int
run_client_server_system(int nargs, char **args)
{
        int check = 0;
        int i, error;
        (void) nargs; /* Avoid "unused variable" warnings */
        (void) args;
        
        kprintf("run_client_server_system: starting up\n");
        
        /* Initialise synch primitives used in the ticket system driver */
        servers_finished = sem_create("servers_finished", 0);
        if(servers_finished == NULL) {
                panic("system: couldn't create servers semaphore\n");
        }

        clients_finished = sem_create("clients_finished", 0);
        if(clients_finished == NULL) {
                panic("system: couldn't create clients semaphore\n");
        }
        
        /* Run any code required to initialise the work queue etc. */
        error = work_queue_setup();
        if (error) panic("work queue setup returned an error\n");

        /* Run the simulation */
        start_client_threads();
        start_server_threads();

        /* Wait for all ticket holders and validators to finish */
        wait_for_client_threads();
        stop_server_threads();

        /* Run any code required to shut down the work queue */
        work_queue_shutdown();

        for (i = 0;i < NUM_SERVERS;i++){
                check += processed[i];
                kprintf("Server %d processed %d requests\n", i, processed[i]);
        }
        kprintf("Giving a total of %d (expected %d)\n", check, NUM_CLIENTS * REQUESTS_TO_MAKE);
        
        /* Done! */
        sem_destroy(clients_finished);
        sem_destroy(servers_finished);
        return 0;
}
/* The main function for the client/server system. */
The main function for the client/server system.
The main function for the client / server system .
int
run_client_server_system(int nargs, char **args)
{
        int check = 0;
        int i, error;
        (void) nargs; 
        (void) args;
        kprintf("run_client_server_system: starting up\n");
        servers_finished = sem_create("servers_finished", 0);
        if(servers_finished == NULL) {
                panic("system: couldn't create servers semaphore\n");
        }
        clients_finished = sem_create("clients_finished", 0);
        if(clients_finished == NULL) {
                panic("system: couldn't create clients semaphore\n");
        }
        error = work_queue_setup();
        if (error) panic("work queue setup returned an error\n");
        start_client_threads();
        start_server_threads();
        wait_for_client_threads();
        stop_server_threads();
        work_queue_shutdown();
        for (i = 0;i < NUM_SERVERS;i++){
                check += processed[i];
                kprintf("Server %d processed %d requests\n", i, processed[i]);
        }
        kprintf("Giving a total of %d (expected %d)\n", check, NUM_CLIENTS * REQUESTS_TO_MAKE);
        sem_destroy(clients_finished);
        sem_destroy(servers_finished);
        return 0;
}
int run_client_server_system ( int nargs , char * * args ) { int check = 0 ; int i , error ; ( void ) nargs ; ( void ) args ; kprintf ( " \n " ) ; servers_finished = sem_create ( " " , 0 ) ; if ( servers_finished == NULL ) { panic ( " \n " ) ; } clients_finished = sem_create ( " " , 0 ) ; if ( clients_finished == NULL ) { panic ( " \n " ) ; } error = work_queue_setup ( ) ; if ( error ) panic ( " \n " ) ; start_client_threads ( ) ; start_server_threads ( ) ; wait_for_client_threads ( ) ; stop_server_threads ( ) ; work_queue_shutdown ( ) ; for ( i = 0 ; i < NUM_SERVERS ; i ++ ) { check += processed [ i ] ; kprintf ( " \n " , i , processed [ i ] ) ; } kprintf ( " \n " , check , NUM_CLIENTS * REQUESTS_TO_MAKE ) ; sem_destroy ( clients_finished ) ; sem_destroy ( servers_finished ) ; return 0 ; }
The main function for the client/server system.
The main function for the client / server system .
/* Avoid "unused variable" warnings */ /* Initialise synch primitives used in the ticket system driver */ /* Run any code required to initialise the work queue etc. */ /* Run the simulation */ /* Wait for all ticket holders and validators to finish */ /* Run any code required to shut down the work queue */ /* Done! */