From b21478ca460e6c07ef571b67147accbd10ef0f9e Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Fri, 11 Jun 2021 12:52:36 +0200 Subject: [PATCH] Scheduler Crash test --- include/base.h | 1 + src/main.c | 41 +++++++++++++++++++++++------------------ src/scheduler.c | 21 +++++++++++++++------ 3 files changed, 39 insertions(+), 24 deletions(-) diff --git a/include/base.h b/include/base.h index 200b67e..f570ca0 100644 --- a/include/base.h +++ b/include/base.h @@ -48,6 +48,7 @@ struct { IntArray_t *arrowList; int nmaxThread; int nmaxCycles; + pthread_t *id; } typedef SchedulerParams_t; // diff --git a/src/main.c b/src/main.c index f9d9f6d..284f70e 100644 --- a/src/main.c +++ b/src/main.c @@ -29,6 +29,27 @@ #define SPACE_SIZE 10000 #define MAX_THREAD 0 +void SchedulerCrashTest(void) +{ + const int maxthread = 2000; + + SchedulerParams_t *parameters = + (SchedulerParams_t*) calloc(1, sizeof(SchedulerParams_t)); + + pthread_t **schedThread = + (pthread_t**) malloc(sizeof(pthread_t*) * maxthread); + + for (int i=0; i < maxthread; i++) { + schedThread[i] = SchedInit(parameters); + } + + for (int i=0; i < maxthread; i++) { + SchedWait(schedThread[i]); + SchedDestroy(schedThread[i]); + } + + free(parameters); +} int main(int argc, char **argv) { @@ -76,23 +97,7 @@ int main(int argc, char **argv) free(parameters); + SchedulerCrashTest(); + return 0; } - - -void SchedulerCrashTest(void) -{ - const int maxthread = 100; - - SchedulerParams_t *parameters = - (SchedulerParams_t*) calloc(1, sizeof(SchedulerParams_t)); - - pthread_t **schedThread = - (pthread_t**) malloc(sizeof(pthread_t*) * maxthread); - - for (int i=0; i < 16; i++) { - schedThread[i] = SchedInit(parameters); - } - - free(parameters); -} diff --git a/src/scheduler.c b/src/scheduler.c index c58c21b..c7aa556 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -31,9 +31,9 @@ static void *GreatScheduler(void *parameters); // -------------------------------------------------------------------------- // pthread_t *SchedInit(SchedulerParams_t *parameters) { - pthread_t *schedThread = (pthread_t*) malloc(sizeof(pthread_t)); - pthread_create(schedThread, NULL, GreatScheduler, parameters); - return schedThread; + parameters->id = (pthread_t*) malloc(sizeof(pthread_t)); + pthread_create(parameters->id, NULL, GreatScheduler, parameters); + return parameters->id; } // -------------------------------------------------------------------------- // @@ -56,9 +56,18 @@ void SchedWait(pthread_t *schedThread) // -------------------------------------------------------------------------- // // Scheduler thread main function // // -------------------------------------------------------------------------- // -static void *GreatScheduler(void *parameters) +static void *GreatScheduler(void *params) { - printf("Printing from thread \n"); - sleep(1); + SchedulerParams_t *parameters = (SchedulerParams_t*) params; + int a = 4; + + + for (int i = 0; i < 45000; i++) { + for (int j = i; j < 45000; j++) { + a = (a + (long)parameters->id) * i * j; + } + } + + printf("thread %d\n", a); return NULL; }