I'v examine the assembly output in Windows of basic singleton implementation of using static variable to be initialized with new class instance from static function.
to my surprise, although the class has process-wide scope, the inner implementation uses access to TLS.
myClass::getInstance()
{
static v = new myClass();
return v;
}
and the assembly output (the first relevant lines) :
push rdi
sub rsp, 40h
mov rdi, rsp
mov ecx, 10h
mov eax, 0CCCCCCCCh
rep stosd
mov [rsp+48h+var_18], 0FFFFFFFFFFFFFFFEh
mov eax, 4
mov eax, eax
mov ecx, cs:_tls_index
mov rdx, gs:58h
mov rcx, [rdx+rcx*8]
Perhaps anybody can provide some insights about why this is needed (maybe performance) ?
thanks