当我组装我的程序时,我看到gcc在使用-O3编译时使用jmp进行第二次pthread_wait_barrier调用.为什么会这样?
使用jmp而不是call会有什么好处.编译器在这里玩什么技巧?我猜它在这里执行尾调用优化.
顺便说一下,我在这里使用静态链接.
__attribute__ ((noinline)) void my_pthread_barrier_wait(
volatile int tid,pthread_barrier_t *pbar )
{
pthread_barrier_wait( pbar );
if ( tid == 0 )
{
if ( !rollbacked )
{
take_checkpoint_or_rollback( ++iter == 4 );
}
}
//getcontext( &context[tid] );
SETJMP( tid );
asm("addr2jmp:");
pthread_barrier_wait( pbar );
// My suspicion was right,gcc was performing tail call optimization,// which was messing up with my SETJMP/LONGJMP implementation,so here I
// put a dummy function to avoid that.
dummy_var = dummy_func();
}
最佳答案
原文链接:https://www.f2er.com/linux/440732.html