Skip to main content

register_main_thread

Function register_main_thread 

Source
pub fn register_main_thread()
Expand description

Put the calling thread on the thread list as C’s _main_.

C’s epicsThreadInit runs once() under a pthread_once (osdThread.c:406-412): it builds a threadInfo for the first thread to touch the epicsThread API, names it _main_, gives it EPICS priority 0 and ellAdds it to pthreadList — without touching that thread’s scheduling. In a C IOC that thread is the one running iocsh(), which is why epicsThreadShowAll there always lists the shell’s own thread.

enter_ioc_thread cannot stand in for this. It bands the thread to the priority it is handed, which C never does to _main_, and it takes the row’s name from std::thread::current().name() — None, and so noname, for a shell started with a bare std::thread::spawn.

Idempotent for the reason C’s guard is a pthread_once: a process has one _main_. The row leaves the list when the registering thread ends, which is where C’s thread-specific-data destructor removes it.