Ниже приведена функция из libcxxabi от LLVM:
void *__cxa_current_primary_exception() throw() {
// get the current exception
__cxa_eh_globals* globals = __cxa_get_globals_fast();
if (NULL == globals)
return NULL; // If there are no globals, there is no exception
__cxa_exception* exception_header = globals->caughtExceptions;
if (NULL == exception_header)
return NULL; // No current exception
if (!isOurExceptionClass(&exception_header->unwindHeader))
return NULL; // Can't capture a foreign exception (no way to refcount it)
if (isDependentException(&exception_header->unwindHeader)) {
__cxa_dependent_exception* dep_exception_header =
reinterpret_cast<__cxa_dependent_exception*>(exception_header);
exception_header = cxa_exception_from_thrown_object(dep_exception_header->primaryException);
}
void* thrown_object = thrown_object_from_cxa_exception(exception_header);
__cxa_increment_exception_refcount(thrown_object);
return thrown_object;
}
globals - переменная локального хранилища потока, и поэтому thrown_object также специфичен для потока.Насколько я понимаю, thrown_object - это исключение, созданное в потоке - каждый поток может выдавать свое собственное исключение.
Но функция __cxa_increment_exception_refcount () выполняет приращение атомарно - почему?Какой сценарий требует, чтобы приращение выполнялось атомарно?