X
xzzy
AllocateNamedDataSlot defined as:
Threads use a local store memory mechanism to store thread-specific data.
The common language runtime allocates a multi-slot data store array to each
process when it is created. The thread can allocate a data slot in the data
store, store and retrieve a data value in the slot, and free the slot for
reuse after the thread expires. Data slots are unique per thread. No other
thread (not even a child thread) can get that data.
I am confused, is a data slot created once for all threads, or for each
thread?
I want to create many threads with the code below.
The goal is to create threads, each new thread being able to read the value
of
myValue=Thread.GetNamedDataSlot("HID"); // the value of HID will be
different for each thread
via
myUID=Thread.GetNamedDataSlot("UID");
in AllJobs.ThisJob
++ Code to create a thread ++
Thread t = new Thread(new ThreadStart(AllJobs.ThisJob));
t.Name = "H" + yHeaderID + "D" + yDetailID;
t.IsBackground = true;
//the next line breaks
t.AllocateNamedDataSlot("UID");
//the previous line breaks
LocalDataStoreSlot ldssUID;
ldssUID=Thread.GetNamedDataSlot("UID");
//the next line doesn't make any sense
Thread.SetData(ldssUID, yUID);
//the previous line doesn't make any sense
t.Start();
++ End of code to create a thread ++
Thank you
Threads use a local store memory mechanism to store thread-specific data.
The common language runtime allocates a multi-slot data store array to each
process when it is created. The thread can allocate a data slot in the data
store, store and retrieve a data value in the slot, and free the slot for
reuse after the thread expires. Data slots are unique per thread. No other
thread (not even a child thread) can get that data.
I am confused, is a data slot created once for all threads, or for each
thread?
I want to create many threads with the code below.
The goal is to create threads, each new thread being able to read the value
of
myValue=Thread.GetNamedDataSlot("HID"); // the value of HID will be
different for each thread
via
myUID=Thread.GetNamedDataSlot("UID");
in AllJobs.ThisJob
++ Code to create a thread ++
Thread t = new Thread(new ThreadStart(AllJobs.ThisJob));
t.Name = "H" + yHeaderID + "D" + yDetailID;
t.IsBackground = true;
//the next line breaks
t.AllocateNamedDataSlot("UID");
//the previous line breaks
LocalDataStoreSlot ldssUID;
ldssUID=Thread.GetNamedDataSlot("UID");
//the next line doesn't make any sense
Thread.SetData(ldssUID, yUID);
//the previous line doesn't make any sense
t.Start();
++ End of code to create a thread ++
Thank you