Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Connecting Threads

Posted on 1998-11-13
3
Medium Priority
?
193 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 180 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 Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

916 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