Solved

thread

Posted on 2011-03-04
2
459 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
ID: 35039097
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
ID: 35039224
Thx!
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 how to clear a vector as well as how to detect empty vectors in C++.

809 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