asst1-Synchronization/kern/asst1/client_server_tester.c
static void
client_thread(void *unused_ptr, unsigned long client_id)
{
        int requests_to_go = REQUESTS_TO_MAKE;
        request_t req;

        (void)unused_ptr; /* Avoid compiler warnings */

        kprintf("Client %ld started\n", client_id);

        /* allocate a single semaphore that we use for all request
           from this client. Each client only has one oustanding
           request at a time. */ 
        req.done = sem_create("Client sem",0); 
        
        if (req.done == NULL) {
                /* This should not happen and there is no reasonable
                   way to recover. */
                panic("Can't create a semaphore??");
        }
        
        while(requests_to_go > 0) {

                /* Initialise the request with a reasonably unique ID
                   number
                 */
                req.number = client_id * REQUESTS_TO_MAKE + requests_to_go - 1;
                req.check = 0;
                
                work_queue_enqueue(&req); /* send the request to the servers */

                P(req.done); /* wait for it to be processed */
                
                if (req.number != ~(req.check)) {
                        panic("My request is corrupt or invalid");
                }

                requests_to_go = requests_to_go - 1;
        }
        
        sem_destroy(req.done); /* we're finished, clean up */
        /* Signal that we're done. */
        kprintf("Client %ld finished\n", client_id);
        V(clients_finished);
}
/********************************************************************************* 
 * The clients thread's function. This function calls
 * work_queue_enqueue REQUESTS_TO_MAKE times and then
 * exits. NUM_CLIENTS threads are started and each run the function.
 */
The clients thread's function. This function calls
work_queue_enqueue REQUESTS_TO_MAKE times and then
exits. NUM_CLIENTS threads are started and each run the function.
The clients thread ' s function . This function calls work_queue_enqueue REQUESTS_TO_MAKE times and then exits . NUM_CLIENTS threads are started and each run the function .
static void
client_thread(void *unused_ptr, unsigned long client_id)
{
        int requests_to_go = REQUESTS_TO_MAKE;
        request_t req;
        (void)unused_ptr; 
        kprintf("Client %ld started\n", client_id);
        req.done = sem_create("Client sem",0); 
        if (req.done == NULL) {
                panic("Can't create a semaphore??");
        }
        while(requests_to_go > 0) {
                req.number = client_id * REQUESTS_TO_MAKE + requests_to_go - 1;
                req.check = 0;
                work_queue_enqueue(&req); 
                P(req.done); 
                if (req.number != ~(req.check)) {
                        panic("My request is corrupt or invalid");
                }
                requests_to_go = requests_to_go - 1;
        }
        sem_destroy(req.done); 
        kprintf("Client %ld finished\n", client_id);
        V(clients_finished);
}
static void client_thread ( void * unused_ptr , unsigned long client_id ) { int requests_to_go = REQUESTS_TO_MAKE ; request_t req ; ( void ) unused_ptr ; kprintf ( " \n " , client_id ) ; req . done = sem_create ( " " , 0 ) ; if ( req . done == NULL ) { panic ( " " ) ; } while ( requests_to_go > 0 ) { req . number = client_id * REQUESTS_TO_MAKE + requests_to_go - 1 ; req . check = 0 ; work_queue_enqueue ( & req ) ; P ( req . done ) ; if ( req . number != ~ ( req . check ) ) { panic ( " " ) ; } requests_to_go = requests_to_go - 1 ; } sem_destroy ( req . done ) ; kprintf ( " \n " , client_id ) ; V ( clients_finished ) ; }
The clients thread's function.
The clients thread ' s function .
/* Avoid compiler warnings */ /* allocate a single semaphore that we use for all request
           from this client. Each client only has one oustanding
           request at a time. */ /* This should not happen and there is no reasonable
                   way to recover. */ /* Initialise the request with a reasonably unique ID
                   number
                 */ /* send the request to the servers */ /* wait for it to be processed */ /* we're finished, clean up */ /* Signal that we're done. */