Threading in Control Extension (API)?

Discussion about recent product features & solutions!
2 posts • Page 1 of 1
daniel.hillenbrand
Posts:1
Joined: Fri Oct 28, 2016 9:38 am

Threading in Control Extension (API)?

Post by daniel.hillenbrand »

Hello Community.

I'm trying to write a kind of tcp echo-server extension (using Socket.hxx) which is able to handle multiple client connections at the same time.
For this i'd need a seperate thread for each client connection to handle recvs and sends.

What's the best way to do multi-threading inside of a control extension?

fmulder
Posts:330
Joined: Wed Feb 03, 2010 9:46 am

Re: Threading in Control Extension (API)?

Post by fmulder »

Each WinCc OA manager is basically single-threaded. Example: when you have a script manager or GUI,. then there's one thread that does the real (C++) work. That is : when you program 50 script threads, then there's only one C++ thread that is switching between these scripts threads.

So, the interface(!) between your control extension and the script 'world' must be single threaded. The script language calls a function in your control extension from its one-and-only thread.

This doesn't mean that you(!) can't create 50 additional threads. The only thing you should not do is doing dpSet()'s or attempting dpGet()'s from your background threads.

What I can imagine is:

1) You have function in your control extension that says 'StartClient()'. This starts your(!) own background thread for one particular client
2) Your background thread does its work and puts its result in global variables
3) You have function in your control extension called 'ReadClientresult' that gets the results form the global data in your control extension

Good luck and share the fun

Frenk Mulder

2 posts • Page 1 of 1