Posix C write () and thread safety

Is there a serialization way C write()so that I can write bytes on a socket shared between k-streams without data loss? I believe the solution to this problem involves blocking user space, and what about scalability? Thank you in advance.

+3
source share
3 answers

I think the correct answer depends on whether your threads are needed to wait for a response synchronously or not. If they just need to write some message to the socket and not wait for the response of the peer, I think the best answer is to have one thread that is designed to write messages from the queue into which other threads put messages. That way, workflows can simply queue their messages and continue to do something else.

, , , (, ). , , , , . , , .

, - . , - select() , .

+4

POSIX, , (2), , , . , , .

0

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

, :

typedef struct my_socket_data_st
{
int msg_id;
#ifdef __debug_build__
    int thread_id;
#endif
size_t data_size_in_bytes;
.... Followed by your data ....
} my_socket_data_t

, , . , . ( , , ) / , , send . , , . , .

0

Source: https://habr.com/ru/post/1783375/


All Articles