It is safe to use the Write function in GNU C using multiple threads

write function calls from multiple threads to the same socket

safely? We wanted to add synchronization to them? This will cause problems, such as a statement of a write / read delay from the network layer to the application layer.

We use the GNU C ++ GCC 4 Libraries in Linux Redhat Enviornment

This is a server-side process where there is only 1 Socket Connectivity between the server and the client server, and the client is on two different computers. Data is sent from the server to the client client to the server

Problem 1 - when the server sends data to the client side (several streams write data on the client side through the same single socket) But the data associated with some of the flows are not deleted on the client side, they do not even get to the network layer of the same machines (tcpdump does not have this data)

Problem 2 - when sending data by the client to the server data, sending to the client is displayed on the server. TCPdump is not received for the server application, which reads from the socket from one stream using the "read" and "select" functions in the loop

We were not able to identify the pattern of occurrence of these problems. We think this happens when so many threads are written to the same socket. We did not synchronize the recording function, hoping that the OS handles synchronization

+5
3

write() - , , .

+1

write() . , . , . , ( , ), - .

0

, write . . . write, ​​ . .

Your data will be recorded in an unspecified order, which is probably not acceptable to you.

0
source

All Articles