Solved

Connecting Threads

Posted on 1998-11-13
3
181 Views
Last Modified: 2011-09-20
Im having a progran in c++ witch makes two kinds of threads , lets call them VeThreads and CuThreads.Each kind has many threads identified uniqelly by a certain key.This key can be found only Twice : first time on the VeThreads and the second time on the CuThreads making them a pair of threads.
I want to pass information between those two threads.
these two threads are made after a connection is made ,  each thread with a different network server.
How do I make this?
Should I use Events?
Is link list a correct way to keep the information need to be passed (there is a possibility that few threads of CuThreads are made before the VeThreads made or viseversa )
and if so how do I make it?
Please give me a full answer include a code example.
Thank you.
Uri
0
Comment
Question by:uri22
3 Comments
 

Expert Comment

by:umzilber
ID: 1177829
Sounds like you need a Semaphore or a Monitor.

0
 
LVL 2

Accepted Solution

by:
abesoft earned 90 total points
ID: 1177830
I think you might want to create an additional level of organization, like a thread-pair manager.  The manager would be a C++ class containing a shared memory area that is protected by a mutex, and it would pass a pointer to itself to the two threads that it spawns.  These threads could send messages back and forth using the manager object.

I would design fns in the thread-manager to SendMessage, CheckMessage, and GetMessage, that would actually get the lock, move the data, and release the lock.

Hope this helps
0
 
LVL 1

Author Comment

by:uri22
ID: 1177831
abesoft thank you for your answer.
I would like to receive a code example for your suggestion.
I will increase points !!!
uri22.
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question