Solved

thread

Posted on 2011-03-04
2
440 Views
Last Modified: 2012-05-11
If 2 threads are trying to send data over TCP/IP socket connection() using the same socket, should both the thread first acquire mutex lock?

if they send() without lock will that cause data loss on receiving side which is waiting on recv()
0
Comment
Question by:learningunix
2 Comments
 
LVL 53

Accepted Solution

by:
Infinity08 earned 250 total points
Comment Utility
When sharing a socket between threads, you should use proper synchronization, so there's never more than one thread that tries to use the socket at the same time.

You could do that with mutexes indeed. Makes sure to lock the mutex before every operation that uses the socket, and unlock it after the operation has finished.

The risk when not doing this, is that you'll garble the data, or worse : corrupt the socket.
0
 

Author Closing Comment

by:learningunix
Comment Utility
Thx!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
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 difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

763 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

6 Experts available now in Live!

Get 1:1 Help Now