A query copies a shared binding's observer slot outside the lock its recorder holds (ThreadSanitizer: 16 warnings on two threads)

Abierto
#2,449 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
48/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
c

Línea de trabajo

Start with vm_slot_query_view in src/vm.c and the observer record path in src/eigenscript.c, then inspect tests/test_tsan.sh and the instruction-count gate. Run the supplied two-thread program and its trajectory of g variant under make tsan; done means no ThreadSanitizer warning on the query or record paths, with the planted race still detectable. Document whether readers see a slot before or after a record and how growth protects storage held by readers.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

area:concurrency area:observer found-by:critic kind:bug

On phase2-numbers at 652b262a, a query of a numeric binding copies its observer slot without the lock that a recording thread holds while it writes the slot. With two OS threads sharing one binding, one assigning it and one reading report of, converged of or stable of it, ThreadSanitizer reports data races between the copy and the record.

g is 1
define reader(n) as:
    local i is 0
    local r is 0
    loop while i < n:
        r is [report of g, converged of g, stable of g]
        i is i + 1
    return r
th is spawn of [reader, 3000]
define writer(n) as:
    local j is 0
    loop while j < n:
        g is j * 1.5
        j is j + 1
    return j
print of (writer of 3000)
print of (thread_join of th)

make tsan, run with setarch -R and TSAN_OPTIONS="halt_on_error=0 exitcode=0": 16 warnings on this program (30 with trajectory of g among the reads). The first:

WARNING: ThreadSanitizer: data race
  Write of size 1 by main thread (mutexes: write M0):
    #0 observer_slot_update_numeric_locked src/eigenscript.c:1229
    #1 observer_slot_update_numeric_shared src/eigenscript.c:1269
    #2 observer_slot_update_numeric src/eigenscript.c:1319
    #3 observer_slot_update src/eigenscript.c:1327
    #4 vm_run_ex src/vm.c:5869
  Previous read by thread T1:
    #0 vm_slot_query_view src/vm.c:459

The read is ObserverSlot q = *s in vm_slot_query_view: the whole slot copied outside the fold lock, then read. The write is the record under that lock. The copy can therefore hold a slot caught between two of the record's writes (a count that is ahead of the ring it counts, or the reverse). That is what the report shows. Whether a reader can also index storage that the recorder has since replaced is NOT shown here (in a live program the storage is made once, when the binding gets its first number, and only a tape's configuration record regrows it); the repair says whether it can.

The tree's own planted race (EIGS_TSAN_OBSERVER_FOLD_OUTSIDE_HOLD=1) raises the count on the same program from 16 to 47, so the hosted thread-sanitizer slice would see a race of this kind if it ran such a program; it runs a fixed slice (tests/test_tsan.sh) that has no reader of a shared numeric binding beside a writer.

Found by an independent review of a bar for another change to the same slot; that change does not touch this.

Done when

  • The program above (and its trajectory of g form) runs under make tsan with no warning whose stack holds vm_slot_query_view or the record path, on a head where the planted race still raises warnings (shown first).
  • The repair says what a reader may see: the slot as it was before a record or after it, never between; and that a growth cannot free what a reader holds. If the copy stays, it is taken under the lock; if a query then pays for the lock on an unshared binding, the cost is measured on the rows of the instruction-count gate.
  • tests/test_tsan.sh gains a program of this shape, so that the hosted slice sees the next one.

— Claude DevBox

Lenguaje dominante
C
Estrellas
3
Forks
7
Merge medio
3 h 28 min
PR fusionados (30 d)
270

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de InauguralSystems/EigenScript

Todos los issues de InauguralSystems/EigenScript

Issues similares

Más issues de C

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.