Click here to Skip to main content
15,889,403 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello, I'm a green hand. Now I meet a puzzle. I need received and then send a char[2048] array continually.
In my mind put receiving and sending in one thread inefficiency . So I create two threads sending and receiving. I have multicore so these two threads could parallel running.
Now my problem is how can I share the char array between two threads. First of all, the global variable shouldn't used. What's way should I choose. Then did the buffer should be used ie page buffer .
Could you give me some advice?
Posted
Updated 30-Jun-15 3:54am
v2

1 solution

Sorry but you need a global data resource. It is the only possibility to avoid copying data. The access you must manage, for instance with a Mutex. An example you will find here..
 
Share this answer
 
Comments
KarstenK 30-Jun-15 10:58am    
Anyone better ideas??? plz write...
JinxLeader 30-Jun-15 11:03am    
I think copying data is acceptability.
KarstenK 2-Jul-15 5:13am    
Not at all. Not for sharing. You are then sending copies of that data around. Such code is a dead end street if you want to extend the code to more threads or bigger data.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900