I have static array with 100 items type of record:
TMy_Array:array[1..100] of T;
where T is:
T = record
A: double;
B: Date;
C: String;
end;
I have n
similar threads modifying their elements in the TMy_Array
TMy_Array[n].A;
TMy_Array[n].B;
TMy_Array[n].C)`.
N
is close to 100
.
I also have 10 other threads that selectively modify any field TMy_Array
.
To achieve this safely should I use critical sections and here comes the question:
Does use only one critical section will not cause overcrowding of fighting and waiting threads to access the array?
Maybe Can I or should I apply 100 critical sections that will protect access to a particular items in T_Array and the will not block other threads?
Var
Cs:array [1..100] of TRTLCriticalSection;
//then for n-thread:
EnterCriticalSection(CS[n]);
TMy_Array[n].A:=…;
TMy_Array[n].B:=…;
TMy_Array[n].C:=…;
LeaveCriticalSection(CS[n]);
Is this a good idea, doesn't overload too much application?
And second question:
Are the TDateTime
(really Double
) and String
atomic data? Can I read (only read) them without worry about conflicts during another thread is writing to it?