Hello together,
is there a way to check whether a ctrl thread (that I started with `startThread()`) is still running?
If I am using waitThread() on an already finished thread, I will get a warning in the Logviewer, which I would like to prevent:
WCCOActrl (3), 2021.07.05 15:27:25.483, CTRL, WARNING, 76, Invalid argument in function,
Line: 108, waitThread
Thanks in advance!
Prevent waitThread() warning message
Search
Re: Prevent waitThread() warning message
It looks like you have to call the function waitThread() before the thread has ended.
Then you get the information when the thread ends.
What is the use case of waiting for a thread to finish?
Best Regards
Leopold Knipp
Senior Support Specialist
Then you get the information when the thread ends.
What is the use case of waiting for a thread to finish?
Best Regards
Leopold Knipp
Senior Support Specialist
Re: Prevent waitThread() warning message
Hi Leo,
thanks for your reply.
Please consider the following example where I have a large number of objects which must go through some time consuming checks. The check for the objects are independent and thus the can be executed in parallel instead of sequentially.
However, all checks must be finished before the method can proceed.
I hope this explains the use case. If not please let me know.
Thanks!
thanks for your reply.
Please consider the following example where I have a large number of objects which must go through some time consuming checks. The check for the objects are independent and thus the can be executed in parallel instead of sequentially.
However, all checks must be finished before the method can proceed.
Code: Select all
public void main()
{
dyn_int diThreadIds;
dyn_anytype daObjects = makeDynAnytype(1,2,3,4,5); //e.g. list of 1000 objects
for (int i = 1; i <= dynlen(daObjects); i++)
{
const int iThreadId = startThread("intenseCalculation", daObjects[i]);
dynAppend(diThreadIds, iThreadId); //create a list of started threads
}
//now wait for the threads to finish
for (int i =1; i <= dynlen(diThreadIds); i++)
{
waitThread(threadIds[i]); //causes the warning
}
// at this point all calculations must be finished to proceed
//doSomethingElse();
}
public void intenseCalculation(anytype someObject)
{
//do something computation intensive
}
Thanks!
Re: Prevent waitThread() warning message
Are you sure that processing the tasks in parallel is faster than in a sequence?
If you want to check if all threads are finished you could implement in your function that at the start of the function a variable is set, e.g. adding an entry to a mapping. When the function is finished the variable is reset.
Instead of checking the thread IDs you check if all variables are reset.
Best Regards
Leopold Knipp
Senior Support Specialist
If you want to check if all threads are finished you could implement in your function that at the start of the function a variable is set, e.g. adding an entry to a mapping. When the function is finished the variable is reset.
Instead of checking the thread IDs you check if all variables are reset.
Best Regards
Leopold Knipp
Senior Support Specialist
Re: Prevent waitThread() warning message
Hey Leo,
yes I am pretty sure the parallel processing is faster. By the way: What happens, if I reach the maximum number of threads on a windows machine? Will the remaining threads be queued and processed sequentially again? I couldnt find anything in the help.
Regarding your proposal:
I also thought of that possiblity, but considered it as a more dirty solution. So in other words, there is no wincc function which allows me to check the run status of a given thread (id)?
Thanks and with best regards,
moTo
yes I am pretty sure the parallel processing is faster. By the way: What happens, if I reach the maximum number of threads on a windows machine? Will the remaining threads be queued and processed sequentially again? I couldnt find anything in the help.
Regarding your proposal:
I also thought of that possiblity, but considered it as a more dirty solution. So in other words, there is no wincc function which allows me to check the run status of a given thread (id)?
Thanks and with best regards,
moTo
Re: Prevent waitThread() warning message
I found this in the Docu. "Windows a maximum of 62 threads can be started!"
In getThreadId()
In getThreadId()
Re: Prevent waitThread() warning message
Why should my solution be a dirty solution?
If you know when your function is finished you can simply save some information that the function is done.
When your functions are defined with a return parameter or a return value you can call the function in your thread and wait until the function is finished or returns an error.
Then the variable with the information if the thread is running is written.
Best Regards
Leopold Knipp
Senior Support Specialist
If you know when your function is finished you can simply save some information that the function is done.
When your functions are defined with a return parameter or a return value you can call the function in your thread and wait until the function is finished or returns an error.
Then the variable with the information if the thread is running is written.
Best Regards
Leopold Knipp
Senior Support Specialist