ngs
ngs copied to clipboard
Adding a field to a type is not thread safe
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)
The solution must be performant
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.
binary semaphore
Performance implications must be checked
can you mention which file I shouldd check?
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.
Fixing typo in get_normal_type_instace_field
can be another issue :)