Question

Context :

Linux debian 64. I am self learning how sockets work and it is very interesting. Single threaded application.

Question :

I am not in the clear with an async/non-blocking question. The socket is set up with fcntl(s, F_SETFL, O_NONBLOCK);

1) What exactly happens if two connections arrive exactly at the same time on one socket ?

When sockets are non blocking, will the code running the socket (call it reception) read the datas and do others stuffs with it in parallel or sequentially ? (single thread app)

I mean, with a non blocking socket, are the incoming requests treated sequentially but very fast (non-blocking operations so only the network becomes the bottleneck not the cpu) or in parallel ?

I ask because I would like to maintain a stack array in the script and cannot afford race condition when pushing datas into it.

Thanks in advance

Was it helpful?

Solution

"Blocking" is very specific term that pertains the scheduler of the operating system: If a user space call blocks, then the operating system deschedules the process (or thread) that is making the call. If an operation is non-blocking, that means that it won't automatically and voluntarily cause your process to go to sleep if the operation cannot succeed, but instead the call returns immediately with a status indicating that there was nothing to be done. (Of course your process can still be descheduled forcefully by preemption, but that's a separate issue.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top