Creating Thread at Runtime
I need to create thread at runtime, destroy and recreate.
I use instruction to create
VDK_ThreadID mythreadID = VDK::CreateThreadEx(VDK_ThreadCreationBlock*);
and
VDK_DestroyThread(mythreadID,true); to destroy.
If i check on the VDK status window i see that the task is created and then destroyed.
Suppose the mythreadID is 8, if i create the same thread again i see the new value is 0x0004008
then again it becomes 0x0008008 and it keeps growing.
The thread number remain the same, only the thread id increase.
Why? Is that normal?
Regards
vdk
Hi,
this is completely normal. There are three separate elements that make up an object ID. These are as follows and are listed in the order they appear from LSB to MSB:
1) An index into the (internal) object table. This is made up of 9 bits.
2) The node ID. In single-processor applications the node ID will be 0. In multi-processor applications the node ID will be the number of the core on which this object exists. This is made up of 5 bits.
3) A count of the number of times the object table index has already been used. This is made up of 18 bits.
A simple diagram of a ThreadID/SemaphoreID could be represented as follows, where each letter represents one bit:
C = Count, N = Node, I = Index
CCCCCCCCCCCCCCCCCCNNNNNIIIIIIIII
It is the 'count' element that is updating each time you create a new thread with the same ID (index in the object table).
Regards,
Craig.
Does ThreadID overflow in this way or i
can continue to create and destroy thread always
keeping the total number of threads working below the limit that i set
in VDK?
Regards
Il 09/11/2011 10:43, CraigG ha scritto:
>
>
Analog Devices EngineerZone <http://ez.analog.com/index.jspa>
>
>
Creating Thread at Runtime
>
reply from CraigG <http://ez.analog.com/people/CraigG> in /Processors
and DSP/ - View the full discussion
Hi,
If you keep on creating and destroying you will never get an error as long as you stay within the limits that you specified in the kernel tab for total number of threads. The "count" will wrap around when we run out of bits.
In the case of fully instrumented or error checking libraries as Craig said in his reply creating and destroying a thread will not return the same ID and you will get a pattern. In the case of the no error checking libraries you will always get the same ID.
As Craig described, we only have a certain number of bits in order to differentiate the IDs. Once we run out of bits for the "count" part of the ID VDK will return back to the beginning.
For example if your thread with ID 2 gets created and destroyed then you will get the following IDs.
Iteration 0 ID 0x2
Iteration 1 ID 0x4002
Iteration 2 ID 0x8002
Iteration 3 ID 0xc002
Iteration 4 ID 0x10002
(...)
Iteration 262144 ID 0x2
(...)
Iteration 524288 ID 0x2
Hope this helps
SFernandez
Hi,
thank you very much. This solved.
Regards
Il 22/11/2011 11:30, SFernandez ha scritto:
>
>
Analog Devices EngineerZone <http://ez.analog.com/index.jspa>
>
>
Creating Thread at Runtime
>
reply from SFernandez <http://ez.analog.com/people/SFernandez> in
/Processors and DSP/ - View the full discussion
This question has been assumed as answered either offline via email or with a multi-part answer. This question has now been closed out. If you have an inquiry related to this topic please post a new question in the applicable product forum.
Thank you,
EZ Admin
Please log in to reply.