Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

thread

Posted on 2011-03-04
2
Medium Priority
?
485 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 53

Accepted Solution

by:
Infinity08 earned 1000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

609 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