example-greenthreads
example-greenthreads copied to clipboard
fixbug
- The asm code
call switch
doesn't work in macOS, it should becall _switch
- Add rust-toochain
Ah, tanks.
I forgot that macos prepend subroutines with "_" even when no_mangle
is specified.
However, I think for the code to work on both linux and macos we need conditional compilation since I believe the suggestion will not work on linux anymore (it will try to call _shwitch
which will not exist since linux doesn't prepend the function name with "_").
I don't have access to a mac at the moment, but if you have the opporunity to try the code on linux and confirm (I guess the playground could work)? If I'm correct then I think we need to do something like this:
#[cfg(not(target_os = "macos"))]
asm!("call switch", in("rdi") old, in("rsi") new, clobber_abi("C"));
#[cfg(target_os = "macos")]
asm!("call _switch", in("rdi") old, in("rsi") new, clobber_abi("C"));
Ah, tanks.
I forgot that macos prepend subroutines with "_" even when
no_mangle
is specified.However, I think for the code to work on both linux and macos we need conditional compilation since I believe the suggestion will not work on linux anymore (it will try to call
_shwitch
which will not exist since linux doesn't prepend the function name with "_").I don't have access to a mac at the moment, but if you have the opporunity to try the code on linux and confirm (I guess the playground could work)? If I'm correct then I think we need to do something like this:
#[cfg(not(target_os = "macos"))] asm!("call switch", in("rdi") old, in("rsi") new, clobber_abi("C")); #[cfg(target_os = "macos")] asm!("call _switch", in("rdi") old, in("rsi") new, clobber_abi("C"));
OK, I would try it later. (Sorry for my late reply...)
@cfsamson Hi, Sir, I have modified and add #[cfg]
flag, I also try it on both macOS and Ubuntu, and it works so well.
Sorry for the delay. Thanks 👍