core :: Sys :: main_thread
# Handle to the program's main thread
fun main_thread: MainThread
do
var cache = main_thread_cache
if cache != null then return cache
main_thread_mutex.lock
# Recheck if cache has been updated since lock has been unlocked/locked
cache = main_thread_cache
if cache != null then
main_thread_mutex.unlock
return cache
end
# Create a `MainThread` exactly once
var thread = new MainThread
thread.native = sys.native_pthread_self
main_thread_cache = thread
main_thread_mutex.unlock
return thread
end
lib/pthreads/pthreads.nit:59,2--81,4