Skip to content

Commit

Permalink
add my broken multithreading test
Browse files Browse the repository at this point in the history
  • Loading branch information
MESYETI committed Aug 17, 2024
1 parent ebc7c96 commit 5fbee77
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions examples/test/multithreading.cal
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# doesn't even work, just trying it out

include "cores/select.cal"
include "std/io.cal"

const __linux_MAP_GROWSDOWN 256
const __linux_CLONE_VM 256
const __linux_CLONE_FS 512
const __linux_CLONE_FILES 1024
const __linux_CLONE_SIGHAND 2048
const __linux_CLONE_PARENT 32768
const __linux_CLONE_THREAD 65536
const __linux_CLONE_IO 2147483648

func __linux_clone begin
__x86_64_pop_rsi
__x86_64_pop_rdi

asm
"mov rax, 56"
"syscall"
end

__x86_64_push_rax
end

const STACK_SIZE 4194304

func new_thread addr function begin
# create stack
let addr stack
STACK_SIZE malloc -> stack
stack printdec new_line
stack STACK_SIZE + -> stack

# flags
__linux_CLONE_VM
__linux_CLONE_FS or
__linux_CLONE_FILES or
__linux_CLONE_SIGHAND or
__linux_CLONE_PARENT or
__linux_CLONE_THREAD or
__linux_CLONE_IO or
stack __linux_clone

dup printdec new_line

if 0 = then
# stinky winky callisto runtime just to get stuff working
asm
"sub rsp, 4096"
"mov r15, rsp"
end
function call
0 exit
end
end

func my_thread begin
65 printdec new_line
end

"hi from parent\n" printstr
&my_thread new_thread

0 comments on commit 5fbee77

Please sign in to comment.