Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cpp unix multithread socket blocking and non-blocking. What is blocking?

At my multithread application I using AF_UNIX type of socket. Seems by default its blocking. The question is whats mean by "blocking"? Is it block the thread when it execute the ::recv or ::send calls or all threads on the application (like fgets do)?

If it block all threads/whole application, I guess need to use non-blocking sockets? If so, please, give the good example of how to set up AF_UNIX non-blocking socket and when need to set non-blocking mode (and how). How to ::recv ? thanks.

like image 829
abrahab Avatar asked Aug 29 '26 00:08

abrahab


2 Answers

Blocking calls make the thread wait for the operation to complete. Use them when your thread cannot continue before the operation has completed, for example due to the data dependency on the input being received.

Non-blocking calls return as soon as the information is buffered for transmission, or the read operation is initiated. Use them when there are no data dependencies.

In general, blocking always means "blocks the current thread", not "block all threads in my process.

like image 182
Sergey Kalinichenko Avatar answered Aug 30 '26 15:08

Sergey Kalinichenko


It only blocks the thread that makes the recv call.

like image 22
Superman Avatar answered Aug 30 '26 15:08

Superman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!