問題を引き起こした巨大なファイバー スケジューラ コードを以下の行にまとめました。
私が期待しているのは、毎回ハンドラーに渡されたコンテキストへのクリーンなリターンです。
私が得るのは "Handler." で、3 回出力された後、セグメンテーション違反が発生します。
#include <ucontext.h>
#include <signal.h>
#include <stdio.h>
ucontext_t currently_executed_context;
void handler_sigusr1(int signum, siginfo_t* siginfo, void* context)
{
currently_executed_context = (*(ucontext_t*)context);
printf("Handler. ");
setcontext(¤tly_executed_context);
}
int main()
{
setbuf(stdout,0);
struct sigaction action_handler;
action_handler.sa_sigaction = handler_sigusr1;
action_handler.sa_flags = SA_SIGINFO;
sigaction(SIGUSR1,&action_handler,NULL);
for(;;) { kill(getpid(),SIGUSR1); sleep(1); }
return 0;
}
2 つの異なる Linux ディストリビューションで gcc-4.4.3 と gcc-4.4.5 の両方を使用しました。