Files
mop3/init/init.c
kamkow1 11a1eb52aa
All checks were successful
Build documentation / build-and-deploy (push) Successful in 36s
Move status codes into a separate header
2026-01-16 19:07:32 +01:00

43 lines
897 B
C

#include <alloc/liballoc.h>
#include <limits.h>
#include <m/proc.h>
#include <m/status.h>
#include <stddef.h>
#include <stdint.h>
#include <string/string.h>
char c = 'a';
int mutex_rid;
void mythread (void) {
for (;;) {
proc_mutex_lock (mutex_rid);
for (size_t i = 0; i < 3; i++)
proc_test ('b');
proc_mutex_unlock (mutex_rid);
}
}
int make_thread (void (*fn) (void)) {
size_t stack_size = 256 * PAGE_SIZE;
void* stack = malloc (stack_size);
if (stack == NULL)
return -ST_OOM_ERROR;
uintptr_t stack_top = (uintptr_t)stack + stack_size;
return proc_spawn_thread (stack_top, stack_size, (void*)fn);
}
void app_main (void) {
mutex_rid = proc_create_resource_mutex (200, RV_PRIVATE);
make_thread (&mythread);
for (;;) {
proc_mutex_lock (mutex_rid);
for (size_t i = 0; i < 3; i++)
proc_test ('a');
proc_mutex_unlock (mutex_rid);
}
}