I am facing one problem regarding threading scenario.
I have three threads in my process. One is subsystem1 thread , second is subsystem2 thread and third one is store manager thread.
Both subsystem1 and subsystem2 thread invoke storemanager thread for making communication with database.
Can anybody help me how to call storemanager thread method or how to pass command to invoke store manager thread method from my sybsystem threads and to get the response back from store manager thread.
Need guidance in this. i am using c++ in linux.
There is no such thing as “invoking” a thread from another thread. Your three threads are running at the same time and independently of each other.
Your store manager thread acts as a worker thread that services requests from the other two threads.
When one of the subsystem threads needs to issue a database operation it sends some form of message to the store manager thread that contains the information about the function that needs to be executed. One way to implement this communication is with a thread-safe queue. The subsystem thread in this case will add a job request to a job queue.
The store manager thread monitors the job queue and executes job requests from the queue as they are added by the other threads. Jobs that are complete are removed from the queue.
Note that the subsystem threads will not block while the store manager thread performs a requested task. Instead, you have to develop a communication mechanism between the threads by which the subsystem threads can find out when a job is complete and obtain information about the result if necessary.
I recommend that you read on thread-safe data structures and synchronization primitives.