Prevent waitThread() warning message

Discussions about product bugs & problems!
Note: This is no replacement for the Official ETM Support!
Search

Post Reply
7 posts • Page 1 of 1
moto3101
Posts: 37
Joined: Tue Aug 22, 2017 2:04 pm

Prevent waitThread() warning message

Post by moto3101 »

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!

User avatar
leoknipp
Posts: 2926
Joined: Tue Aug 24, 2010 7:28 pm

Re: Prevent waitThread() warning message

Post by leoknipp »

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

moto3101
Posts: 37
Joined: Tue Aug 22, 2017 2:04 pm

Re: Prevent waitThread() warning message

Post by moto3101 »

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.

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
}
I hope this explains the use case. If not please let me know.
Thanks!

User avatar
leoknipp
Posts: 2926
Joined: Tue Aug 24, 2010 7:28 pm

Re: Prevent waitThread() warning message

Post by leoknipp »

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

moto3101
Posts: 37
Joined: Tue Aug 22, 2017 2:04 pm

Re: Prevent waitThread() warning message

Post by moto3101 »

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

User avatar
kilianvp
Posts: 443
Joined: Fri Jan 16, 2015 10:29 am

Re: Prevent waitThread() warning message

Post by kilianvp »

I found this in the Docu. "Windows a maximum of 62 threads can be started!"

In getThreadId()

User avatar
leoknipp
Posts: 2926
Joined: Tue Aug 24, 2010 7:28 pm

Re: Prevent waitThread() warning message

Post by leoknipp »

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

Post Reply
7 posts • Page 1 of 1