Questions tagged [nonblocking]

Non-blocking mode I/O either transfers at least one byte or returns immediately with an error or end of stream. Non-blocking algorithms refer to use of concurrency without the usual mutual exclusion primitives, guaranteeing that thread operations will not block indefinitely. This is usually handled with atomic value modification (increment/decrement) and/or reading (compare-and-exchange) operations.. It isn't clear which this tag is intended for.

1597 questions
32
votes
3 answers

Examples/Illustration of Wait-free And Lock-free Algorithms

I've read that wait-free causes all threads to finish independently and lock-free ensures the program as a whole completes. I couldn't quite get it. Can anyone give an example (java) illustrating this. EDIT: Does lock-free mean a program without…
softwarematter
  • 28,015
  • 64
  • 169
  • 263
31
votes
3 answers

Python/Erlang: What's the difference between Twisted, Stackless, Greenlet, Eventlet, Coroutines? Are they similar to Erlang processes?

My incomplete understanding is that Twisted, Stackless, Greenlet, Eventlet, Coroutines all make use of async network IO and userland threads that are very lightweight and quick to switch. But I'm not sure what are the differences between them. Also…
Continuation
  • 12,722
  • 20
  • 82
  • 106
30
votes
6 answers

Non-blocking (async) DNS resolving in Java

Is there a clean way to resolve a DNS query (get IP by hostname) in Java asynchronously, in non-blocking way (i.e. state machine, not 1 query = 1 thread - I'd like to run tens of thousands queries simultaneously, but not run tens of thousands of…
GreyCat
  • 16,622
  • 18
  • 74
  • 112
29
votes
5 answers

Write PHP non blocking applications

I want to write non-blocking applications. I use apache2, but I was reading about nginx and its advantage with respect to apache processes. I am considering changing out apache for nginx. My question is, is it possible to write non-blocking web…
Gonzalo Bahamondez
  • 1,371
  • 1
  • 16
  • 37
28
votes
3 answers

Python socket.accept nonblocking?

Is there a way I can use python's socket.accept() in a non-blocking way that simply runs it and lets me just check if it got any new connections? I really don't want to use threading. Thanks.
pajm
  • 1,788
  • 6
  • 24
  • 30
26
votes
8 answers

Read timeout using either urllib2 or any other http library

I have code for reading an url like this: from urllib2 import Request, urlopen req = Request(url) for key, val in headers.items(): req.add_header(key, val) res = urlopen(req, timeout = timeout) # This line blocks content = res.read() The…
Björn Lindqvist
  • 19,221
  • 20
  • 87
  • 122
26
votes
3 answers

What is the point/purpose of Ruby EventMachine, Python Twisted, or JavaScript Node.js?

I don't understand what problem these frameworks solve. Are they replacements for a HTTP server like Apache HTTPD, Tomcat, Mongrel, etc? Or are they more? Why might I use them... some real world examples? I've seen endless examples of chat rooms…
CCw
  • 271
  • 3
  • 3
25
votes
4 answers

Greater-than compare-and-swap

As the title suggests, I'm looking for a compare-and-swap implementation, but with greater-than comparison: if(newValue > oldValue) { oldValue = newValue; } where oldValue is some global shared state and newValue is private to each thread,…
Tudor
  • 61,523
  • 12
  • 102
  • 142
25
votes
1 answer

How do Jetty and other containers leverage NIO while sticking to the Servlet specification?

I'm new to NIO, and I am trying to figure out how Jetty leverages NIO. My understanding of how traditional servlet containers that use Blocking IO service a request is as follows: A request arrives A thread is allocated to process the request and…
rationalrevolt
  • 663
  • 1
  • 6
  • 13
24
votes
2 answers

Non-blocking javascript and css in modern browsers. Is it still needed?

I am playing a little with some non-blocking JavaScript loading. This means I have a small snippet of JavaScript in my head, and load all my external files at runtime. I even took it a little further to load CSS non-blocking. I see the articles I…
Saif Bechan
  • 16,551
  • 23
  • 83
  • 125
24
votes
1 answer

Node.js server with multiple concurrent requests, how does it work?

I know node.js is a single threaded, asynchronous, non blocking i/o. I've read a lot about that. e.g PHP uses one thread per request but node uses only one thread for all, like that. Suppose there are three requests a, b, c arriving at same time at…
Siddharth
  • 505
  • 2
  • 4
  • 9
24
votes
1 answer

Is O_NONBLOCK being set a property of the file descriptor or underlying file?

From what I have been reading on The Open Group website on fcntl, open, read, and write, I get the impression that whether O_NONBLOCK is set on a file descriptor, and hence whether non-blocking I/O is used with the descriptor, should be a property…
Daniel Trebbien
  • 38,421
  • 18
  • 121
  • 193
24
votes
3 answers

Single Threaded Event Loop vs Multi Threaded Non Blocking Worker in Node.JS

Node.JS's most significant advantage is its non-blocking nature. It's single-threaded, so it doesn't need to spawn a new thread for each new incoming connection. Behind the event-loop (which is in fact single-threaded), there is a "Non-blocking…
Christian
  • 6,961
  • 10
  • 54
  • 82
24
votes
2 answers

When a non-blocking send() only transfers partial data, can we assume it would return EWOULDBLOCK the next call?

Two cases are well-documented in the man pages for non-blocking sockets: If send() returns the same length as the transfer buffer, the entire transfer finished successfully, and the socket may or may not be in a state of returning…
22
votes
6 answers

How are Node.js+Socket.io+MongoDB webapps truly asynchronous?

I have a good old-style LAMP webapp. A week ago I needed to add a push notification mechanism to it. Therefore, what I did was to add node.js+socket.io on the server and poll the MySQL database every 10 seconds using node.js to check whether there…
Dan
  • 15,948
  • 20
  • 63
  • 92