xiaoxiang781216 commented on PR #6197: URL: https://github.com/apache/incubator-nuttx/pull/6197#issuecomment-1134795742
> Now there are still two open questions: > > 1. Where is the part prior to the call to _exit() supposed to go now ? There are now two definitions of exit() and this one must be removed, but there is work that needs to be done prior to _exit(). > > ``` > void exit(int status) > { > FAR struct tcb_s *tcb = this_task(); > > /* Only the lower 8-bits of status are used */ > > status &= 0xff; > > #ifdef HAVE_GROUP_MEMBERS > /* Kill all of the children of the group, preserving only this thread. > * exit() is normally called from the main thread of the task. pthreads > * exit through a different mechanism. > */ > > group_kill_children(tcb); > #endif > > #if !defined(CONFIG_DISABLE_PTHREAD) && !defined(CONFIG_PTHREAD_MUTEX_UNSAFE) > /* Recover any mutexes still held by the canceled thread */ > > pthread_mutex_inconsistent(tcb); > #endif > > /* Perform common task termination logic. This will get called again later > * through logic kicked off by _exit(). However, we need to call it before > * calling _exit() in order to handle atexit() and on_exit() callbacks and > * so that we can flush buffered I/O (both of which may required > * suspending). > */ > > nxtask_exithook(tcb, status, false); > > /* Then "really" exit. Only the lower 8 bits of the exit status are > * used. > */ > > _exit(status); > } > ``` One method is: 1. Rename _exit to up_exit and add the prototype to arch.h 2. Rename _exit to up_exit inside _exit 3. Remove nxtask_exithook from _exit 4. Rename exit to _exit Another method is: 1. merge arch/*/src/up_exit.c into sched_exit.c 2. Remove nxtask_exithook from _exit 3. Rename exit to _exit The second method need move up_fullcontextrestore declaration to arch/*include/syscall.h like up_saveusercontext > > 2. What do I do about this, this no longer compiles ? @Ouss4 ? > > ``` > static void *esp_thread_semphr_get(void) > { > int ret; > int i; > void *sem; > struct tcb_s *tcb = this_task(); > struct task_group_s *group = tcb->group; > > for (i = 0; i < CONFIG_SCHED_EXIT_MAX; i++) > { > if (group->tg_exit[i].func.on == esp_thread_semphr_free) > { > break; > } > } > > if (i >= CONFIG_SCHED_EXIT_MAX) > { > sem = esp_semphr_create(1, 0); > if (!sem) > { > wlerr("ERROR: Failed to create semaphore\n"); > return NULL; > } > > ret = on_exit(esp_thread_semphr_free, sem); > if (ret < 0) > { > wlerr("ERROR: Failed to bind semaphore\n"); > esp_semphr_delete(sem); > return NULL; > } > } > else > { > sem = group->tg_exit[i].arg; > } > > return sem; > } > ``` Why not use Thread local storage or simply define any array to the mapping by self: ``` struct xxx_s { pid_t id; FAR sem_t *sem; } g_id2sem[xxx]; ``` it look better than to hack atexit logic @Ouss4? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org