我在做一個線程庫(使用uncontext.h更改上下文)。 我的函數是void類型的,我不能返回。但是,即使我不回,編譯時出現此警告:警告:'noreturn'函數確實返回
dccthread.c: In function ‘dccthread_init’:
dccthread.c:184:1: warning: ‘noreturn’ function does return [enabled by default]
}
這是功能的簡化代碼(不包括一些細節):
void dccthread_init(void (*func), int param) {
int i=0;
if (gerente==NULL)
gerente = (dccthread_t *) malloc(sizeof(dccthread_t));
getcontext(&gerente->contexto);
gerente->contexto.uc_link = NULL;
gerente->contexto.uc_stack.ss_sp = malloc (THREAD_STACK_SIZE);
gerente->contexto.uc_stack.ss_size = THREAD_STACK_SIZE;
gerente->contexto.uc_stack.ss_flags = 0;
gerente->tid=-1;
makecontext(&gerente->contexto, gerente_escalonador, 0);
if (principal==NULL)
principal = (dccthread_t *) malloc(sizeof(dccthread_t));
getcontext(&principal->contexto);
principal->contexto.uc_link = NULL;
principal->contexto.uc_stack.ss_sp = malloc (THREAD_STACK_SIZE);
principal->contexto.uc_stack.ss_size = THREAD_STACK_SIZE;
principal->contexto.uc_stack.ss_flags = 0;
makecontext(&principal->contexto, func, 1, param);
swapcontext(&gerente->contexto, &principal->contexto);
}
請注意,我不隨時返回。但海灣合作委員會給我這個警告。有誰知道有什麼問題?
這讓人懷疑。但我不知道我會怎麼做。但這是一個開始,我會尋找一種方法。謝謝。 –
沒問題。很高興我可以幫忙一下。 – Jasper