Changing OPC structure in multi-threaded environment

12 views
Skip to first unread message

OPC Testtesttest

unread,
Jun 9, 2022, 7:55:00 AMJun 9
to open62541
Hi,

we have one thread running the opc-server (UA_Server_run(...)) and a main application thread. I was wondering whether it is safe to add/remove nodes from the main thread while the opc-server thread is running.

Example: opc-server thread is in a data-read callback for a given variable node and at the same time the main thread is deleting that node.

Will the stack make sure that the node is not deleted prior to exiting the callback ? Or do I have to take measures from application side (e.g. stopping the opc-server thread or use mutexes) ?

Best regards,
Henning

Julius Pfrommer

unread,
Jun 9, 2022, 9:42:24 AMJun 9
to open62541
Hi,

you can enable the flag UA_MULTITHREADING >= 100.
This adds a mutex to protect the server when it is accessed from multiple threads.

We have a Github pull request that enables this by default.
So from the next release on multithreading will come automatic. RIght now it needs to be enabled in the build flags.

Regards, Julius

Julius Pfrommer

unread,
Jun 9, 2022, 9:44:39 AMJun 9
to open62541
Also note that some of the server methods are marked as UA_THREADSAFE in the API.
Those are the methods that are safe to call from multiple threads.

Regards, Julius
Reply all
Reply to author
Forward
0 new messages