From 85277edb62a73265f347296e51be1e59f6b3fe4f Mon Sep 17 00:00:00 2001 From: Rajshekar Kalayappan Date: Thu, 9 Jan 2025 13:11:46 +0530 Subject: [PATCH] initial commit. simple SUV done. --- .gitignore | 4 + Monitor_synthesizer/README | 2 + README | 2 + SUV/makefile | 5 + SUV/train_station_simulator_racy_logic.cpp | 103 +++++++++++++++++++++ instrumentation_synthesizer/README | 2 + 6 files changed, 118 insertions(+) create mode 100644 .gitignore create mode 100644 Monitor_synthesizer/README create mode 100644 README create mode 100644 SUV/makefile create mode 100644 SUV/train_station_simulator_racy_logic.cpp create mode 100644 instrumentation_synthesizer/README diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ebb9b9b --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.out +*.o +*.swp + diff --git a/Monitor_synthesizer/README b/Monitor_synthesizer/README new file mode 100644 index 0000000..2cc1b67 --- /dev/null +++ b/Monitor_synthesizer/README @@ -0,0 +1,2 @@ +Monitor Synthesizer code goes here + diff --git a/README b/README new file mode 100644 index 0000000..bb62547 --- /dev/null +++ b/README @@ -0,0 +1,2 @@ +Have a nice top-level makefile or bash / python scripts that evolves with each assignment + diff --git a/SUV/makefile b/SUV/makefile new file mode 100644 index 0000000..eb16943 --- /dev/null +++ b/SUV/makefile @@ -0,0 +1,5 @@ +build_racy_logic: train_station_simulator_racy_logic.cpp + g++ train_station_simulator_racy_logic.cpp -o train_station_simulator_racy_logic.out + +run_racy_logic: build_racy_logic + ./train_station_simulator_racy_logic.out diff --git a/SUV/train_station_simulator_racy_logic.cpp b/SUV/train_station_simulator_racy_logic.cpp new file mode 100644 index 0000000..3595863 --- /dev/null +++ b/SUV/train_station_simulator_racy_logic.cpp @@ -0,0 +1,103 @@ +#include +#include +#include +#include +using namespace std; + +void sleep_ms(unsigned long milliseconds) +{ + struct timespec ts; + ts.tv_sec = milliseconds / 1000ul; + ts.tv_nsec = (milliseconds % 1000ul) * 1000000; + nanosleep(&ts, NULL); +} + +// $TO_INSTRUMENT$ +bool is_T0_running; +// $TO_INSTRUMENT$ +bool is_T0_waiting_to_enter_station; +// $TO_INSTRUMENT$ +bool is_T0_in_station; +// $TO_INSTRUMENT$ +bool is_T1_running; +// $TO_INSTRUMENT$ +bool is_T1_waiting_to_enter_station; +// $TO_INSTRUMENT$ +bool is_T1_in_station; + +void *train_logic(void *train_number) +{ + int my_number = *(int *)train_number; + bool *is_T_running; + bool *is_T_in_station; + bool *is_T_waiting_to_enter_station; + if(my_number == 0) + { + is_T_running = &is_T0_running; + is_T_waiting_to_enter_station = &is_T0_waiting_to_enter_station; + is_T_in_station = &is_T0_in_station; + } + else if(my_number == 1) + { + is_T_running = &is_T1_running; + is_T_waiting_to_enter_station = &is_T1_waiting_to_enter_station; + is_T_in_station = &is_T1_in_station; + } + int num_station_visits = 0; + while(num_station_visits < 10) + /* + * Note that typically we study systems that run infinitely. + * However, for the sake of this laboratory study, we will + * study finite runs. + */ + { + //Run for some time in the range [3, 5] seconds. Running time in multiples of 100 milliseconds. + *is_T_running = true; + *is_T_in_station = false; + *is_T_waiting_to_enter_station = false; + cout << "train " << my_number << " : " << *is_T_running << " : " << *is_T_waiting_to_enter_station << " : " << *is_T_in_station << "\n"; + sleep_ms(3000 + clock()%21 * 100); + + //Wait to enter station + *is_T_running = false; + *is_T_in_station = false; + *is_T_waiting_to_enter_station = true; + cout << "train " << my_number << " : " << *is_T_running << " : " << *is_T_waiting_to_enter_station << " : " << *is_T_in_station << "\n"; + + //Stand in the station for 1 second + *is_T_running = false; + *is_T_in_station = true; + *is_T_waiting_to_enter_station = false; + cout << "train " << my_number << " : " << *is_T_running << " : " << *is_T_waiting_to_enter_station << " : " << *is_T_in_station << "\n"; + sleep_ms(1000); + + num_station_visits++; + } + + return NULL; +} + +int main() +{ + pthread_t thread0, thread1; + int iret0, iret1; + int thread_number0 = 0, thread_number1 = 1; + + iret0 = pthread_create(&thread0, NULL, train_logic, &thread_number0); + if(iret0) + { + fprintf(stderr,"Error - pthread_create() return code: %d\n",iret0); + exit(EXIT_FAILURE); + } + iret1 = pthread_create(&thread1, NULL, train_logic, &thread_number1); + if(iret1) + { + fprintf(stderr,"Error - pthread_create() return code: %d\n",iret1); + exit(EXIT_FAILURE); + } + + pthread_join(thread0, NULL); + pthread_join(thread1, NULL); + + exit(EXIT_SUCCESS); +} diff --git a/instrumentation_synthesizer/README b/instrumentation_synthesizer/README new file mode 100644 index 0000000..f1b76fb --- /dev/null +++ b/instrumentation_synthesizer/README @@ -0,0 +1,2 @@ +Instrumentation Synthesizer code goes here +