Open Ethernet Networking (OpEN) API Guide and Reference Manual
3.6.0.3
|
This document provides a brief description of multi-threaded application support using OpEN APIs. It provides the following services:
The main function initializes its OpEN API RPC service by calling openapiClientRegisterEnhanced() with the OPEN_REGISTER_FLAGS_THREADED flag and waits for the RPC service in switchdrvr to start. A Client Handle is returned by openapiClientRegisterEnhanced() which is used to invoke the OpEN APIs needed for checking the ICOS version. The main function creates two thread instances of the "Check Connect" task and starts them. It then waits for all threads to complete and displays their result status, after which the application exits.
Meanwhile, each Check Connect task instance initializes its own OpEN API RPC service by calling openapiClientRegisterEnhanced() with the OPEN_REGISTER_FLAGS_THREADED flag and waits for the RPC service in switchdrvr to start. A Client Handle is returned by openapiClientRegisterEnhanced() which is used to invoke the OpEN APIs used by the task. The task threads call openapiConnectivityCheck() 1000 times in rapid succession and display the summary OK/Error counts collected during each iteration. A total of 8 iterations are performed per thread, with an intervening sleep interval whose duration is specified by the main application when creating the thread.
multi_threaded_app_example.c is a sample application that demonstrates the use of multiple threads executing within a single process. multi_threaded_app_example is started from the command line.
# ./multi_threaded_app_example
ICOS version = 8.3.0.0
Starting 2 process threads...
[check-connect-2] Running Check Connect task instance 2 (8 iterations, 3 second sleep interval)...
[check-connect-1] Running Check Connect task instance 1 (8 iterations, 1 second sleep interval)...
[check-connect-1] OpEN API test iteration 1 – Attempts=1000: OK=1000 Error=0 (Last Error RC = 0)
[check-connect-2] OpEN API test iteration 1 – Attempts=1000: OK=1000 Error=0 (Last Error RC = 0)
[check-connect-1] OpEN API test iteration 2 – Attempts=1000: OK=1000 Error=0 (Last Error RC = 0)
[check-connect-1] OpEN API test iteration 3 – Attempts=1000: OK=1000 Error=0 (Last Error RC = 0)
[check-connect-2] OpEN API test iteration 2 – Attempts=1000: OK=1000 Error=0 (Last Error RC = 0)
[check-connect-1] OpEN API test iteration 4 – Attempts=1000: OK=1000 Error=0 (Last Error RC = 0)
[check-connect-1] OpEN API test iteration 5 – Attempts=1000: OK=1000 Error=0 (Last Error RC = 0)
[check-connect-2] OpEN API test iteration 3 – Attempts=1000: OK=1000 Error=0 (Last Error RC = 0)
[check-connect-1] OpEN API test iteration 6 – Attempts=1000: OK=1000 Error=0 (Last Error RC = 0)
[check-connect-1] OpEN API test iteration 7 – Attempts=1000: OK=1000 Error=0 (Last Error RC = 0)
[check-connect-2] OpEN API test iteration 4 – Attempts=1000: OK=1000 Error=0 (Last Error RC = 0)
[check-connect-1] OpEN API test iteration 8 – Attempts=1000: OK=1000 Error=0 (Last Error RC = 0)
Thread instance 1 exited. Status: COMPLETE
[check-connect-2] OpEN API test iteration 5 – Attempts=1000: OK=1000 Error=0 (Last Error RC = 0)
[check-connect-2] OpEN API test iteration 6 – Attempts=1000: OK=1000 Error=0 (Last Error RC = 0)
[check-connect-2] OpEN API test iteration 7 – Attempts=1000: OK=1000 Error=0 (Last Error RC = 0)
[check-connect-2] OpEN API test iteration 8 – Attempts=1000: OK=1000 Error=0 (Last Error RC = 0)
Thread instance 2 exited. Status: COMPLETE
All process threads have completed. Exiting application.