Hi,
Some comments:
1] If you add Thread=ZSUtilities.GetCurrentThreadId() inside the DoWork subroutines you should use different variable names (Thread1 etc) in each subroutine. It is unlikely, but not impossible that they could be used at the same time, so its just good practice to do this.
2] The main purpose of this example is to show the syntax. Note for example the difference in how DoWork1,2 are called compared to DoWork3. num1, num2 and num3 are just used to give each othe subroutines more work to do, the double loops in the DoWork subroutines are there just to take some time.
3] I don't think there can be a systematic reason for one thread number to be faster than another. It is up to the OS how to allocate CPU time for different threads and can vary for many different reasons. It actually takes some time to set up the threads so often there is no speed advantage unless the actual work in the thread takes significant time. If I set num1=num2=num3, then they all finish about the same time, although DoWork1 is usually first (it starts first) and DoWork3 usually beats DoWork2 and sometimes DoWork1, maybe due to it being called directly rather than indirectly throuugh LDCall.Function which has a small overhead. I guess you could set up careful timings for this, but all I think you will see is small variation in how the OS is setting things up and probably no obvious reasons - could depend on loads of other things going on - hundreds of threads starting and finishing all the time.
4] To find what may be available (e.g. that LDCall.CallAsync exists) then either use this forum to ask as you did, or using SBPrime Tools->Search Extensions. For me, searching for "thread" gives stuff in FCExtensions, LDPhysics, ZSEnvironment, ZSThread, ZSUtilities. Searching for "async" also gives LDCall, LDftp, LDUtilities, LDWaveForm. A few searches with some likely keywords usually turns up whatever there may be.
Is there something in the sample program that you are unsure about, or some code you have that you are trying to do asynchronously (in parallel using threads). Is there a specific objective you have using threads.
Some comments:
1] If you add Thread=ZSUtilities.GetCurrentThreadId() inside the DoWork subroutines you should use different variable names (Thread1 etc) in each subroutine. It is unlikely, but not impossible that they could be used at the same time, so its just good practice to do this.
2] The main purpose of this example is to show the syntax. Note for example the difference in how DoWork1,2 are called compared to DoWork3. num1, num2 and num3 are just used to give each othe subroutines more work to do, the double loops in the DoWork subroutines are there just to take some time.
3] I don't think there can be a systematic reason for one thread number to be faster than another. It is up to the OS how to allocate CPU time for different threads and can vary for many different reasons. It actually takes some time to set up the threads so often there is no speed advantage unless the actual work in the thread takes significant time. If I set num1=num2=num3, then they all finish about the same time, although DoWork1 is usually first (it starts first) and DoWork3 usually beats DoWork2 and sometimes DoWork1, maybe due to it being called directly rather than indirectly throuugh LDCall.Function which has a small overhead. I guess you could set up careful timings for this, but all I think you will see is small variation in how the OS is setting things up and probably no obvious reasons - could depend on loads of other things going on - hundreds of threads starting and finishing all the time.
4] To find what may be available (e.g. that LDCall.CallAsync exists) then either use this forum to ask as you did, or using SBPrime Tools->Search Extensions. For me, searching for "thread" gives stuff in FCExtensions, LDPhysics, ZSEnvironment, ZSThread, ZSUtilities. Searching for "async" also gives LDCall, LDftp, LDUtilities, LDWaveForm. A few searches with some likely keywords usually turns up whatever there may be.
Is there something in the sample program that you are unsure about, or some code you have that you are trying to do asynchronously (in parallel using threads). Is there a specific objective you have using threads.