As David points out, trying to do thread context switching from a C function would be extremely hard. In addition to the frame and stack pointers, you are likely changing the "from" and "to" pointers out from under yourself. Best stick to assembly language so you are not fighting the compiler. See threads/x86/switch.S in the OSKit sources for example.