From: root Date: Thu, 17 Sep 2015 12:50:15 +0000 (+0200) Subject: 03a done X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=6ef9df24af633025d2a8501f9ea50deedb95e1c9;p=des2015.git 03a done --- diff --git a/mart/ex03/Makefile b/mart/ex03/Makefile new file mode 100644 index 0000000..bbbff1d --- /dev/null +++ b/mart/ex03/Makefile @@ -0,0 +1,9 @@ +CFLAGS=$(shell xeno-config --xeno-cflags) -lnative -lrtdk +LDFLAGS=$(shell xeno-config --xeno-ldflags) + +BINARIES=$(addprefix ex03,a b c) + +all: $(BINARIES) + +clean: + $(RM) -v $(BINARIES) *.o diff --git a/mart/ex03/ex03a.c b/mart/ex03/ex03a.c index 195a64f..7d6b061 100644 --- a/mart/ex03/ex03a.c +++ b/mart/ex03/ex03a.c @@ -18,39 +18,37 @@ int global = 0; void taskOne(void *arg) { - int i; - for (i=0; i < ITER; i++) - { - rt_printf("I am taskOne and global = %d................\n", ++global); - } + int i; + for (i=0; i < ITER; i++) + { + rt_printf("I am taskOne and global = %d................\n", ++global); + } } void taskTwo(void *arg) { - int i; - for (i=0; i < ITER; i++) - { - rt_printf("I am taskTwo and global = %d----------------\n", --global); - } + int i; + for (i=0; i < ITER; i++) + { + rt_printf("I am taskTwo and global = %d----------------\n", --global); + } } int main(int argc, char* argv[]) { - /* Perform auto-init of rt_print buffers if the task doesn't do so */ - rt_print_auto_init(1); + /* Perform auto-init of rt_print buffers if the task doesn't do so */ + rt_print_auto_init(1); - /* Avoids memory swapping for this program */ - mlockall(MCL_CURRENT|MCL_FUTURE); + /* Avoids memory swapping for this program */ + mlockall(MCL_CURRENT|MCL_FUTURE); - /* create the two tasks */ - rt_task_create(&t1, "task1", 0, 1, 0); - rt_task_create(&t2, "task2", 0, 1, 0); + /* create the two tasks */ + rt_task_create(&t1, "task1", 0, 1, 0); + rt_task_create(&t2, "task2", 0, 1, 0); - /* start the two tasks */ - rt_task_start(&t1, &taskOne, 0); - rt_task_start(&t2, &taskTwo, 0); + /* start the two tasks */ + rt_task_start(&t1, &taskOne, 0); + rt_task_start(&t2, &taskTwo, 0); - return 0; + return 0; } - - diff --git a/mart/ex03/ex03b.c b/mart/ex03/ex03b.c new file mode 100644 index 0000000..9c6f544 --- /dev/null +++ b/mart/ex03/ex03b.c @@ -0,0 +1,64 @@ +#include +#include +#include +#include + +#include +#include +#include + +#include + +#define ITER 10 + +static RT_TASK t1; +static RT_TASK t2; +RT_SEM sem; + +int global = 0; + +void taskOne(void *arg) +{ + int i; + for (i=0; i < ITER; i++) + { + rt_sem_p(&sem, TM_INFINITE); + rt_printf("I am taskOne and global = %d................\n", ++global); + rt_sem_v(&sem); + } +} + +void taskTwo(void *arg) +{ + int i; + for (i=0; i < ITER; i++) + { + rt_sem_p(&sem, TM_INFINITE); + rt_printf("I am taskTwo and global = %d----------------\n", --global); + rt_sem_v(&sem); + } +} + +int main(int argc, char* argv[]) +{ + /* Perform auto-init of rt_print buffers if the task doesn't do so */ + rt_print_auto_init(1); + + /* Avoids memory swapping for this program */ + mlockall(MCL_CURRENT|MCL_FUTURE); + + /* create the two tasks */ + rt_task_create(&t1, "task1", 0, 1, 0); + rt_task_create(&t2, "task2", 0, 1, 0); + + /* create semaphore and start in blocked mode */ + rt_sem_create(&sem, "sem", 0, S_FIFO); + + /* start the two tasks */ + rt_task_start(&t1, &taskOne, 0); + rt_task_start(&t2, &taskTwo, 0); + + /* release the semaphore */ + rt_sem_v(&sem); + return 0; +} diff --git a/mart/ex03/ex03c.c b/mart/ex03/ex03c.c new file mode 100644 index 0000000..195a64f --- /dev/null +++ b/mart/ex03/ex03c.c @@ -0,0 +1,56 @@ +#include +#include +#include +#include + +#include +#include +#include + +#include + +#define ITER 10 + +static RT_TASK t1; +static RT_TASK t2; + +int global = 0; + +void taskOne(void *arg) +{ + int i; + for (i=0; i < ITER; i++) + { + rt_printf("I am taskOne and global = %d................\n", ++global); + } +} + +void taskTwo(void *arg) +{ + int i; + for (i=0; i < ITER; i++) + { + rt_printf("I am taskTwo and global = %d----------------\n", --global); + } +} + +int main(int argc, char* argv[]) +{ + /* Perform auto-init of rt_print buffers if the task doesn't do so */ + rt_print_auto_init(1); + + /* Avoids memory swapping for this program */ + mlockall(MCL_CURRENT|MCL_FUTURE); + + /* create the two tasks */ + rt_task_create(&t1, "task1", 0, 1, 0); + rt_task_create(&t2, "task2", 0, 1, 0); + + /* start the two tasks */ + rt_task_start(&t1, &taskOne, 0); + rt_task_start(&t2, &taskTwo, 0); + + return 0; +} + + diff --git a/mart/ex03/explanations.txt b/mart/ex03/explanations.txt new file mode 100644 index 0000000..f53474f --- /dev/null +++ b/mart/ex03/explanations.txt @@ -0,0 +1,6 @@ +3a. +Since the first task is started first the main loop halts until it's finished. + +3b. + +3c.