From 3340d2f85f954b40e180b71889ffc16e027ef3e9 Mon Sep 17 00:00:00 2001 From: yf00319 <yf00319@surrey.ac.uk> Date: Wed, 24 May 2023 08:52:08 +0000 Subject: [PATCH] fix logs --- banking_app/banking_app.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/banking_app/banking_app.c b/banking_app/banking_app.c index 4711a8b..2c6573d 100644 --- a/banking_app/banking_app.c +++ b/banking_app/banking_app.c @@ -1,4 +1,3 @@ - #include <stdio.h> #include <stdlib.h> #include <unistd.h> @@ -6,6 +5,7 @@ #include "types.h" #include "thread.h" #include <time.h> +#include <sys/time.h> #include <libpmemobj/base.h> #include <libpmemobj/pool_base.h> #include <libpmemobj/types.h> @@ -27,9 +27,13 @@ struct pmem_obj_root{ char initialised; struct thread_context th; }; +#define arr_len 30 +pthread_t thread_array[arr_len]; void transfer_funds(struct customer *list, int source, int dest, int amt); + + void *p_region(void *context){ // double x; @@ -64,12 +68,11 @@ void *p_region(void *context){ int source_new_balance = (int)TM_SHARED_READ(tc->data[source].balance); int destination_new_balance = (int)TM_SHARED_READ(tc->data[destination].balance); - printf("index: %d, name: %s \n", source, tc->data[source].name); - printf("index: %d, name: %s \n", destination, tc->data[destination].name); + printf("source_index: %d, name: %s \n", source, tc->data[source].name); + printf("destination_index: %d, name: %s \n", destination, tc->data[destination].name); printf("source balance: %d / destination balance: %d / amount: %d\n", source_new_balance, destination_new_balance, amount); if(source_new_balance >= amount){ - printf("source balance: %d / destination balance: %d / amount: %d\n", source_new_balance, destination_new_balance, amount); //printf("source: %s, %d", &tc->data[source].name, &tc-> //transfer_funds(tc->data, source, destination, amount); @@ -232,17 +235,24 @@ MAIN(argc, argv) for(;;){ GOTO_REAL(); - int arr_len = 30; TM_STARTUP(arr_len); - pthread_t thread_array[arr_len]; +// pthread_t thread_array[arr_len]; srand(time(NULL)); + + struct timeval start, stop; + gettimeofday(&start, NULL); +// time(&rawtime); +// timeinfo = localtime(&rawtime); + +// printf("%lld", rawtime); + for (int i = 0; i < arr_len; i++) { pthread_create(&thread_array[i], NULL, p_region, tc); // sleep(10); } for (int i = 0; i < arr_len; i++) { - printf("joining: %llu\n", (unsigned long long)thread_array[i]); + //printf("joining: %llu\n", (unsigned long long)thread_array[i]); pthread_join(thread_array[i], NULL); } @@ -289,7 +299,7 @@ MAIN(argc, argv) } } while(choice != 0); */ - TM_SHUTDOWN(); + // TM_SHUTDOWN(); display(tc->data, number_of_customers); @@ -303,9 +313,14 @@ MAIN(argc, argv) if(bank_balance != new_bank_balance){ printf("Inconsistent state detected \n"); break; - } + } + + gettimeofday(&stop, NULL); + printf("took %lu us\n", (stop.tv_sec - start.tv_sec) * 1000000 + stop.tv_usec - start.tv_usec); + + break; - break; + } //free(tc); -- GitLab