[英]Is it a good practice to terminate kernel thread with “return” or “do_exit()”?
[英]Exit thread with return
我有一個小問題,我希望找到可以幫助的人。 我正在嘗試使用 ucontext 在 c 中開發一個線程庫,並且我已經為此開發了基本功能。 所以現在我的問題是我想考慮用戶用 return 而不是我的退出函數完成他的函數的情況。
是否可以知道線程上下文是否已完成並在用戶在其函數中使用 retutn 時獲取返回值?
是否可以知道線程上下文是否已完成並在用戶在其函數中使用 retutn 時獲取返回值?
是的:您提供自己的函數,並用它初始化上下文。 您將一個指向用戶函數的指針和參數(如果有)傳遞給您的函數。 該函數將類似於:
void *thread_top(void *(*user_fn)(void*), void *arg)
{
void *ret = (*user_fn)(arg);
// Do whatever is desirable for "ret" and terminate the context here.
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.