От: | _hum_ | ||
Дата: | 25.04.18 15:56 | ||
Оценка: |
const long nSize = 100000;
std::vector<float> v(nSize);
#pragma omp parallel for
for (long i = 0; i < nSize; ++i)
v[i] = sqrt(i);
И там же дальше проводятся рассуждения, что такой подход довольно ограничительный, и что намного разумнее:The standard says:
Except where explicitly specified in this standard, it is implementation-defined which functions in the Standard C++ library may be recursively reentered.
The standard should mandate that all standard functions must be reentrant, unless otherwise specified.
I would
completely ignore the possibility of of any standard function being non-reentrant, except when it is clear that the function cannot be reasonably made reentrant.
От: | watchmaker | ||
Дата: | 25.04.18 16:23 | ||
Оценка: | +4 |
This definition of reentrancy differs from that of thread-safety in multi-threaded environments. A reentrant subroutine can achieve thread-safety, but being reentrant alone might not be sufficient to be thread-safe in all situations. Conversely, thread-safe code does not necessarily have to be reentrant (see below for examples).
От: | _hum_ | ||
Дата: | 25.04.18 19:12 | ||
Оценка: |
This definition of reentrancy differs from that of thread-safety in multi-threaded environments. A reentrant subroutine can achieve thread-safety, but being reentrant alone might not be sufficient to be thread-safe in all situations. Conversely, thread-safe code does not necessarily have to be reentrant (see below for examples).
Этот вариант отличается от англоязычного тем, что требуется корректная работа не только самой функци, но целой программы, в которой она вызывается.Компьютерная программа в целом или её отдельная процедура называется реентера́бельной (от англ. reentrant — повторно входимый), если она разработана таким образом, что одна и та же копия инструкций программы в памяти может быть совместно использована несколькими пользователями или процессами. При этом второй пользователь может вызвать реентерабельный код до того, как с ним завершит работу первый пользователь и это как минимум не должно привести к ошибке, а при корректной реализации не должно вызвать потери вычислений (то есть не должно появиться необходимости выполнять уже выполненные фрагменты кода).
От: | watchmaker | ||
Дата: | 25.04.18 19:51 | ||
Оценка: |
И это не имеет отношения к реентабельности.[container.requirements.dataraces]
1 For purposes of avoiding data races (20.5.5.9), implementations shall consider the following functions to be
const: begin, end, rbegin, rend, front, back, data, find, lower_bound, upper_bound, equal_range, at
and, except in associative or unordered associative containers, operator[].
2 Notwithstanding 20.5.5.9, implementations are required to avoid data races when the contents of the contained
object in different elements in the same container, excepting vector<bool>, are modified concurrently.
От: | _hum_ | ||
Дата: | 25.04.18 20:24 | ||
Оценка: |
о. спасибо.W>[container.requirements.dataraces]
W>1 For purposes of avoiding data races (20.5.5.9), implementations shall consider the following functions to be
W>const: begin, end, rbegin, rend, front, back, data, find, lower_bound, upper_bound, equal_range, at
W>and, except in associative or unordered associative containers, operator[].
W>2 Notwithstanding 20.5.5.9, implementations are required to avoid data races when the contents of the contained
W>object in different elements in the same container, excepting vector<bool>, are modified concurrently.
Реентерабельность тесно связана с безопасностью функции в многопоточной среде (thread-safety), тем не менее, это разные понятия (в практическом программировании под современные ОС термин «реентерабельный» на деле равносилен термину «thread-safe»).
Alghtought the use of critical sections to implement thread safety is a significiant improvement over the use of pre-function mutexes, it is still somewhat inefficient because there is a cost to locking and unlocking a mutex. A reinterant function achieves thread safety without the use of mutexes. It does this by avoiding the use of global and static variables. Any information that must be returned to the caller or maintained between calls to the fucntion, is stored in buffer allocated by caller
Это как бы противоречит написанному в англоязычной вики (и соответствует написанному в русскоязычной ).An operation is "thread-safe" if it can be performed from multiple threads safely, even if the calls happen simultaneously on multiple threads.
An operation is re-entrant if it can be performed while the operation is already in progress (perhaps in another context). This is a stronger concept than thread-safety, because the second attempt to perform the operation can even come from within the same thread.