Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is it safe to use Write Function in GNU C using multiple threads

write function calls from multiple threads to the same socket

is it safe ? Do we wanted to add a syncronization among them? Will it cause fro problems like Application getting delayed write/read from the Network Layer to Application layer

We are using GNU C++ libraries GCC 4 on Linux Redhat Enviornment

This is a Server Side Process where There is only 1 Socket Connectivity between Server & Client Server & Client are on 2 diffent Machines Data is send from Server to Client Client to Server

Problem 1-when Server Send Data to Client Side (Multiple Threads Write data to client Side through the Same Single Socket) But Data Writen from the some of the threads are not gone to client side it doesnot even gone to the network Layer of the same machine (Tcpdump does not have that data)

Problem 2-when Client Send data to Server Data Send By Client is shown in the the server's TCPdump not received for the server application which is reading from the socket from a single thread usinga "read" & "select" functions in a loop

We were unable to identify the pattern of occuring these Problems We think This happend when so many multiple threads are writing to Same socket We are not syncronizationed write function hoping that OS is handling the syncronization

like image 271
samira Avatar asked Nov 14 '22 03:11

samira


1 Answers

write() is a system call, not a library function, and system calls are generally guaranteed to be atomic.

like image 69
user207421 Avatar answered Dec 23 '22 08:12

user207421