ngs icon indicating copy to clipboard operation
ngs copied to clipboard

Adding a field to a type is not thread safe

Open ilyash-b opened this issue 6 years ago • 6 comments

Race condition exists when two threads execute simultaneously obj.myfield = 1 for any myfield that is not already present in one of the objects of the type (and therefore in the type definition data structure)

ilyash-b avatar Jul 30 '18 04:07 ilyash-b

The solution must be performant

ilyash-b avatar Sep 24 '22 11:09 ilyash-b

as there might be many fields to be added to a type, I think binary semaphore can be used to prevent the race condition. Let me think little further.

antonio-pedro99 avatar Oct 17 '22 01:10 antonio-pedro99

binary semaphore

Performance implications must be checked

ilyash-b avatar Oct 18 '22 05:10 ilyash-b

can you mention which file I shouldd check?

antonio-pedro99 avatar Oct 18 '22 06:10 antonio-pedro99

set_normal_type_instance_field() in obj.c.

( Tracing: .= in vm.c -> native_set_field_nti_str_any() in vm.c (nti - normal type instance) -> set_normal_type_instance_field() in obj.c )

The idea is stolen from node.js - not every object has the map between fields and their values. The type has the map between field's names and an index. Each object of the type has array to be used with that index. The array has values of the fields. See get_normal_type_instace_field() and set_normal_type_instance_field() for access.

ilyash-b avatar Oct 19 '22 08:10 ilyash-b

Fixing typo in get_normal_type_instace_field can be another issue :)

ilyash-b avatar Oct 19 '22 08:10 ilyash-b