7.2. Threading model¶
- Thread-safe operations:
These operations can block a thread while the same
Connector is used in
a different thread.
All operations on different
Connector instances are thread-safe.
Applications can implement their own thread-safety mechanism around a
instance. The following section provides an example.
7.2.1. Protecting calls to Connector¶
This example shows how to use the Python
threading package to
protect calls to the same
import threading connector = rti.Connector("MyParticipantLibrary::MyParticipant", "ShapeExample.xml") lock = threading.RLock() def read_thread(): with lock: # Protect access to methods on the same Connector input = connector.get_input("MySubscriber::MySquareReader") input.wait() # wait outside the lock with lock: # Take the lock again input.take(); for sample in input.samples.valid_data_iter: print(sample.get_dictionary()) def write_thread(): with lock: # Protect access to methods on the same Connector output = connector.get_output("MyPublisher::MySquareWriter") output.instance['x'] = 10 output.write() # Spawn read_thread and write_thread...