Best solution for inter-thread communication?
I am working on an application for the linux operating system, using posix threads, and this is completely new to me. I have searched high and low, and it seems there is no single recommendation for all inter-thread communication - I have a feeling this is because different scenarios call for different solutions.
My scenario is as follows: I have one main thread that starts two threads on start up that deal with reading and writing from/to the same socket, respectively.
The reader thread will read data from the socket when possible, and then relay it on to the main thread, which will parse it and call certain event handlers if the data received contained certain messages.(It's an IRC bot like I mentioned in my last post, and it supports modules in that the user can add modules to it that contain functions that are to be called when the wanted message is received from the server; e.g. module libmod.so is loaded, and the symbol privmsg_handler added to the event chain for PRIVMSG. Then it will be called every time a privmsg is received).
Herein lies my question: What is the best way to pass data between threads? My initial thought was pipes, but AFAIK, this is mostly used for IPC. Is there a reason I don't want to be using pipes for ITC?
Thing is, it would be optimal if I could come up with a solution that would allow the custom module functions provided by the user to read input directly, if they wanted. This would aid in the creation of things like file server(Stateful stuff? Wrong term?), where the first command might be !listfiles, and then it would be waiting for a filename after that.
AFAIK, if I used named pipes, I could accomplish this. Or do these pipes only two ends like in reality, and would opening it in a module thus close it in the main thread or something similar?
I got told about something called System V IPC, but as long as there's nothing bad about using pipes for ITC, I think I will stick with them.
I would really appreciate any input on this matter, even if you have a completely different method to accomplish this, as we are still in the design phase.