协程:makecontext参数问题
看网上的协程库的示例, 看到makecontext的使用有像如下这样的:来自云风的协程库:
makecontext(&C->ctx, (void (*)(void)) mainfunc, 2, (uint32_t)ptr, (uint32_t)(ptr>>32));
某makecontext示例代码:
//低版本glibc实现问题不支持64bit指针
p1 = (uint32_t)((0x00000000FFFFFFFF)&((uint64_t)(&ctx))>>32); //高位
p2 = (uint32_t)(0x00000000FFFFFFFF&(uint64_t)(&ctx)); //低位
makecontext(&u, (void(*)(void))(&call_thread), 2, p1, p2);
不理解makecontext为什么一定要传入64位指针;
后来看makecontext源码 :
http://www.oschina.net/code/explore/glibc-2.9/sysdeps/unix/sysv/linux/x86_64/makecontext.c
看makecontext源码,发现这一段话:
Handle arguments. www.zzzyk.com
The standard says the parameters must all be int values. This is
an historic accident and would be done differently today. For
x86-64 all integer values are passed as 64-bit values and
therefore extending the API to copy 64-bit values instead of
32-bit ints makes sense. It does not break existing
functionality and it does not violate the standard which says
that passing non-int values means undefined behavior.
补充:综合编程 , 其他综合 ,