Solved

thread

Posted on 2011-03-04
2
466 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Suggested Solutions

Title # Comments Views Activity
Template syntax for variable length arrays 9 75
Create a path if not exists 7 92
What is sub-make ? 2 71
Copy output image from TWindowsMediaPlayer 6 48
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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 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.

820 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