I am trying to get Thread A to communicate with Thread B. I should be using message passing between threads to do this but I am trying to find some sample source code which explains message passing.
Does anyone have any good link to some sample source code (in C) which explains message passing ?
While not having a link, there are many ways to implement this.
First is to use sockets. This is not actually a method I would recommend, as it can be quite a lot of work to get it to work right.
The second is related to the first method, and is to use something called anonymous pipes.
A third way, and the one I usually use, is “inspired” by how message passing worked on the old Amiga operating system: Simply use a queue. Since memory is shared between threads it’s easy to just pass pointers around. Use one queue per thread. Just remember to protect the queues, with something like a mutex.
The platform you are using will probably have other ways of communication. Do a Google search for (for example) linux ipc.