我为qemu-arm编写了这个汇编代码来运行,有时它会给出分段错误,有时它会永远循环,我不知道为什么......
当我在线程函数中进行睡眠时,它似乎正在工作,否则就没有。
.data
msg_0:
.ascii "enter thread\n"
.align 2
msg_1:
.ascii "exit thread\n"
.align 2
msg_2:
.ascii "created thread\n"
.align 2
.text
.global main
.global f_conc
.global create_thread
f_conc:
ldr r0, =msg_0
bl puts
mov r0, #0
bl fflush
mov r0, #2
#bl sleep
ldr r0, =msg_1
bl puts
mov r0, #0
bl fflush
mov r0, #0
bl pthread_exit
create_thread:
push {lr}
#reserve space
mov r0, #4
bl malloc
mov r4, r0
mov r1, #0
ldr r2, =f_conc
mov r3, #0
bl pthread_create
#ldr r0, =msg_2
#bl puts
mov r0, r4
pop {pc}
main:
push {lr}
bl create_thread
bl create_thread
bl create_thread
mov r0, #7
#bl sleep
mov r0, #0
bl pthread_exit
pop {pc}