--- /dev/null
+CFLAGS=$(shell xeno-config --xeno-cflags)
+LDFLAGS=$(shell xeno-config --xeno-ldflags)\
+ -lnative -lrtdk -Xlinker -rpath\
+ -Xlinker $(shell xeno-config --libdir)
+
+BINARIES=$(addprefix ex08,a b)
+
+all: $(BINARIES)
+
+clean:
+ $(RM) -v $(BINARIES)
--- /dev/null
+#include <stdio.h>
+#include <signal.h>
+#include <unistd.h>
+#include <sys/mman.h>
+
+#include <native/task.h>
+#include <native/timer.h>
+#include <native/sem.h>
+
+#include <rtdk.h>
+
+static RT_TASK tl;
+static RT_TASK tm;
+static RT_TASK th;
+RTIME timeblock = 1e7;
+RT_SEM sem;
+
+int global = 0;
+
+void t_low(void *arg)
+{
+ int i;
+ for(i = 0; i<3; i++){
+ rt_sem_p(&sem, TM_INFINITE);
+ rt_printf("Low priority task locks semaphore\n");
+ rt_task_sleep(timeblock*3);
+ rt_printf("Low priority task unlocks semaphore\n");
+ rt_sem_v(&sem);
+ }
+ rt_printf(".....Low priority task ends\n");
+}
+
+void t_med(void *arg)
+{
+ rt_task_sleep(timeblock*2);
+ int i;
+ for(i = 0; i<10; i++){
+ rt_printf("Medium task running\n");
+ rt_timer_spin(timeblock);
+ }
+ rt_printf(".....Medium priority task ends\n");
+}
+
+void t_high(void *arg)
+{
+ rt_task_sleep(timeblock*3);
+ int i;
+ for(i = 0; i<3; i++){
+ rt_printf("High priority task tries to locks semaphore\n");
+ rt_sem_p(&sem, TM_INFINITE);
+ rt_printf("High priority task locks semaphore\n");
+ rt_timer_spin(timeblock*3);
+ rt_printf("High priority task unlocks semaphore\n");
+ rt_sem_v(&sem);
+ }
+ rt_printf(".....High priority task ends\n");
+}
+
+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(&tl, "t_low", 0, 49, 0);
+ rt_task_create(&tm, "t_med", 0, 50, 0);
+ rt_task_create(&th, "t_high", 0, 51, 0);
+
+ /* create semaphore and start in blocked mode */
+ rt_sem_create(&sem, "sem", 1, S_PRIO);
+
+ /* start the two tasks */
+ rt_task_start(&tl, &t_low, 0);
+ rt_task_start(&tm, &t_med, 0);
+ rt_task_start(&th, &t_high, 0);
+
+ pause();
+}
--- /dev/null
+#include <stdio.h>
+#include <signal.h>
+#include <unistd.h>
+#include <sys/mman.h>
+
+#include <native/task.h>
+#include <native/timer.h>
+#include <native/mutex.h>
+
+#include <rtdk.h>
+
+static RT_TASK tl;
+static RT_TASK tm;
+static RT_TASK th;
+RTIME timeblock = 1e7;
+RT_MUTEX mutex;
+
+int global = 0;
+
+void t_low(void *arg)
+{
+ int i;
+ for(i = 0; i<3; i++){
+ rt_mutex_acquire(&mutex, TM_INFINITE);
+ rt_printf("Low priority task locks semaphore\n");
+ rt_task_sleep(timeblock*3);
+ rt_printf("Low priority task unlocks semaphore\n");
+ rt_mutex_release(&mutex);
+ }
+ rt_printf(".....Low priority task ends\n");
+}
+
+void t_med(void *arg)
+{
+ rt_task_sleep(timeblock*2);
+ int i;
+ for(i = 0; i<10; i++){
+ rt_printf("Medium task running\n");
+ rt_timer_spin(timeblock);
+ }
+ rt_printf(".....Medium priority task ends\n");
+}
+
+void t_high(void *arg)
+{
+ rt_task_sleep(timeblock*3);
+ int i;
+ for(i = 0; i<3; i++){
+ rt_printf("High priority task tries to locks semaphore\n");
+ rt_mutex_acquire(&mutex, TM_INFINITE);
+ rt_printf("High priority task locks semaphore\n");
+ rt_timer_spin(timeblock*3);
+ rt_printf("High priority task unlocks semaphore\n");
+ rt_mutex_release(&mutex);
+ }
+ rt_printf(".....High priority task ends\n");
+}
+
+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(&tl, "t_low", 0, 49, 0);
+ rt_task_create(&tm, "t_med", 0, 50, 0);
+ rt_task_create(&th, "t_high", 0, 51, 0);
+
+ /* create semaphore and start in blocked mode */
+ rt_mutex_create(&mutex, "mutex");
+
+ /* start the two tasks */
+ rt_task_start(&tl, &t_low, 0);
+ rt_task_start(&tm, &t_med, 0);
+ rt_task_start(&th, &t_high, 0);
+
+ pause();
+}