windows - Threading and Thread Safety in C -


when there common set of global data needs shared among several threaded processes, typically have used thread token protect shared resource:

enter image description here

edit - 7/22/15 (to incorporate atomics viable option, per jens comments)

my [first] question is, in c, if write routines in such way guarantee each thread accesses one, , 1 element of array:

enter image description here

is there reason think asynchronous , simultaneous access different indices of same unprotected array (as shown in diagram) problem?

second question: given an object can accessed atomic entity, in presence of asynchronous interrupts ( c99 - 7.14 signal handling ) using atomics effective method thread protection otherwise unprotected variable?

enter image description here

edit (clarifications address questions in comments point):
- specifics application:
- target os: windows 7/8/10
- compiler : c99 compliant (cannot use c11, include _atomic() type specifier )
- h/w : intel i7 family

this (which looks c standard of sort) http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf sayeth:

note 1 2 threads of execution can update , access separate memory locations without interfering each other

note 13 compiler transformations introduce assignments potentially shared memory location not modified abstract machine precluded standard, since such assignment might overwrite assignment different thread in cases in abstract machine execution not have encountered data race. includes implementations of data member assignment overwrite adjacent members in separate memory locations. preclude reordering of atomic loads in cases in atomics in question may alias, since may violate "visible sequence" rules.

the way understand it, preclude quamrana's concerns , guarantee unprotected writes separate memory locations should never result in undefined behavior if there no data race.


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -