syncDict
Syntax
syncDict(keyObj, valueObj, [sharedName])
or
syncDict(keyType, valueType, [sharedName])
Arguments
keyObj a vector indicating dictionary keys.
valueObj a vector indicating dictionary values.
keyType the data type of dictionary keys.
valueType the data type of dictionary values.
sharedName a string. If it is specified, the dictionary is shared across sessions.
Details
Return a thread-safe dictionary that allows concurrent read and write by multiple threads. The system supports the following data categories for keys: Logical, Integral, Floating and Temporal. There are no restrictions regarding the data type of the values of a dictionary.
Examples
$ x=1 2 3
$ y=4.5 7.8 4.3
$ z=syncDict(x,y);
3->4.3
1->4.5
2->7.8
$ z=syncDict(INT,DOUBLE)
$ z[5]=7.9
$ z;
5->7.9
$ syncDict(INT,DOUBLE, `sn)
$ sn[5 6]=10.99 2.33
$ sn[5];
10.99
In the following example, concurrent write to dictionary z1 results in server crash.
$ def task1(mutable d,n){
$ for(i in 0..n){
$ d[i]=i*2
$ }
$ }
$ def task2(mutable d,n){
$ for(i in 0..n){
$ d[i]=i+1
$ }
$ }
$ n=10000000
$ z1=dict(INT,INT)
$ jobId1=submitJob("task1",,task1,z1,n)
$ jobId2=submitJob("task2",,task2,z1,n);
In comparison, concurrent write to the thread-safe dictionary z2 is allowed.
$ z2=syncDict(INT,INT)
$ jobId3=submitJob("task1",,task1,z2,n)
$ jobId4=submitJob("task2",,task2,z2,n)
$ getJobReturn(jobId3, true)
$ getJobReturn(jobId4, true)
$ z2;