Solved

Connecting Threads

Posted on 1998-11-13
3
178 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now