FAQ Database Discussion Community


Pattern to communicate with a thread

java,multithreading,design-patterns,synchronization,nonblocking
I have a class OuterClass that contains a List and there is a thread ListWorker that is started in OuterClass that is adding some elements to the list. Based on a function call to OuterClass , it should be able to inform the thread to delete elements. What is the...

PyAudio Responsive Recording

python,user-interface,asynchronous,nonblocking,pyaudio
I've seen the recording tutorial on the PyAudio website for recording a fixed length recording, but I was wondering how I could do the same with a non-fixed recording? Bascially, I want to create buttons to start and end the recording but I haven't found anything on the matter. Any...

How java nio ServerSocketChannel accept works?

java,sockets,network-programming,nio,nonblocking
I can't get how NIO works under the hood. Here is a sample code: // Create the server socket channel ServerSocketChannel server = ServerSocketChannel.open(); // nonblocking I/O server.configureBlocking(false); // host-port 8000 server.socket().bind(new java.net.InetSocketAddress(host,8000)); // Create the selector Selector selector = Selector.open(); // Recording server to selector (type OP_ACCEPT) server.register(selector,SelectionKey.OP_ACCEPT); while...

Why does NodeJS NOT use Promise for the readFile API?

javascript,node.js,asynchronous,promise,nonblocking
In the book https://pragprog.com/book/tbajs/async-javascript, I found this: Node’s early iterations used Promises in its nonblocking API. However, in February 2010, Ryan Dahl made the decision to switch to the now-familiar callback(err, results...) format, on the grounds that Promises are a higher-level construct that belongs in “userland.” It looks quite confusing...

python Non-block read file

python,python-2.7,nonblocking
I want to read a file with non-block mode. So i did like below import fcntl import os fd = open("./filename", "r") flag = fcntl.fcntl(fd.fileno(), fcntl.F_GETFD) fcntl.fcntl(fd, fcntl.F_SETFD, flag | os.O_NONBLOCK) flag = fcntl.fcntl(fd, fcntl.F_GETFD) if flag & os.O_NONBLOCK: print "O_NONBLOCK!!" But the value flag still represents 0. Why..? i...

ZeroMQ pattern for load balancing work across workers based on idleness

zeromq,nonblocking,asyncsocket
I have a single producer and n workers that I only want to give work to when they're not already processing a unit of work and I'm struggling to find a good zeroMQ pattern. 1) REQ/REP The producer is the requestor and creates a connection to each worker. It tracks...

In NodeJS, will `fs.writeFile()` in event handler block the main thread at a certain time point?

node.js,multithreading,file,asynchronous,nonblocking
I know fs.writeFile() is asynchronous and will be delayed to be executed. For example: fs.writeFile() console.log("non-blocking") // last statement of an event handler function will print non-blocking immediately and then that thread will spend time to execute the operations to write files. However, if the NodeJS App is single-threaded. When...

Lua: Get Keyboard Input Without Blocking

io,lua,nonblocking
I've started working on a little project in Lua that involves making a text-based interface that updates constantly, and allows keyboard input for interaction. I need a way to get keyboard input, but I also need it to either not block, or have some kind of timeout (which can be...

Can a Tornado RequestHandler attend requests, while waiting for a Future to finish?

tornado,nonblocking,coroutine,requesthandler,concurrent.futures
Can a single Tornado RequestHandler class attend new requests, while waiting for a Future to finish in one of its instances? I was debugging a Tornado coroutine that called a ThreadPoolExecutor and I noticed that, while the coroutine was waiting for the executor to finish, the RequestHandler was blocked. So...

Play framework, promises, non blocking thread programming

java,playframework,promise,nonblocking
What profit is from function1() over function2() (except little parallelism when two GET query is executing)? In my opinion controller thread is non blocked in both cases, but one of background thread must be blocked when waiting for result. For better example when we look at function3() we see that...

Context Switches on Sleeping/Waiting Threads

multithreading,threadpool,nonblocking,context-switch,context-switching
I'm trying to understand how operating systems handle context switching in different models to better understand why NIO performance is better in cases of large peaks in the number of requests. Apart from the fact that there may be a limit to the number of threads, I'm curious how blocking...

Server running at 30% CPU after sudden client disconnect with Java NIO, will my fix work?

java,nio,nonblocking
I have an non-blocking NIO server I wrote, for the most part it functions as expected with normal use; however I noticed that on occasion it sticks at 30% CPU usage for some reason. After a lot of time trying to force the bug I eventually triggered it when I...

Node.js - single thread, non-blocking?

javascript,node.js,nonblocking
I am learning Node.js and I have read that Node.js is single threaded and non-blocking. I have a good background in JavaScript and I do understand the callbacks, but what I don't really understand is how Node.js can be single threaded and run code in the background. Isn't that contradictory?...

How to execute “synchronous” javascript call to server without locking up the browser

javascript,browser,request,nonblocking,synchronous
this may be a stupid question, but....is there a way in Javascript to synchronously wait for a specific request to finish without locking the browser thread? The goal is to call server-side using ajax and executing piece of code after the call is finished AND avoiding callback (hell). Some simple...

Non-blocking communication buffer manipulation before test or wait

mpi,nonblocking
The MPI standard states that once a buffer has been given to a non-blocking communication function, the application is not allowed to use it until the operation has completed (i.e., until after a successful TEST or WAIT function). Is this also applied to the situation below: I have a buffer...

Implementing nonblocking thread-safe list

java,list,thread-safety,nonblocking
Is it possible to implement nonblocking thread-safe list using ConcurrentHashMap as a backing where you use the index as the key and elements as the values?

why non-blocking write to disk doesn't return EAGAIN or EWOULDBLOCK?

c,linux,kernel,nonblocking,syscall
I modified a program from APUE, the program first open a file, then mark the fd as non-blocking, then continue write to the fd until write return -1. I think since disk I/O is slow, when write buffers in OS is nearly full, the write system call will return -1,...

Where to put return next() properly in Restify module in node.js?

javascript,node.js,nonblocking,restify
Here is an example for querying user from database then if user exists, another query for phone: module.exports = function (username, req, res, next) { var query = User.where('username', new RegExp('^' + username + '$', 'i')); query.findOne(function (err, user) { if (err) { res.send("error"); //## position D } else if...

Make InputStream non-blocking

java,inputstream,nonblocking
Currently I have a server that listens for connections (it is a basic highscore server for a mobile game I have), loops through the connections every 1000ms and listens for any incoming data. public void readData(Connection c) throws IOException { PacketBuffer readBuffer = new PacketBuffer(Server.PACKET_CAPACITY); int packetSize = c.getIn().read(); c.getIn().mark(packetSize);...

Perl check if nonblocking file read/ write has finished

perl,nonblocking
I am learning about non blocking io in perl. I have the following script, where I am trying to write to a file in a non blocking fashion. Is this the correct way to do it ? If not what is the correct way ? I am having trouble simulating...

Watch directory using scheduled executor instead of hard loop in Java

java,multithreading,nonblocking,executorservice,watch
In my previous question I was warking on a simple exercise that watched a directory for file changes. I took the code from this oracle docs, and it worked with no problem, except for the little unchecked cast warning I was unsure about. The next problem I have with this...

How to exit outer function early from one of many inner non-blocking function calls?

javascript,node.js,asynchronous,nonblocking
I'm writing a naive implementation of async.parallel as a learning exercise. Here is the description from the docs: parallel(tasks, [callback]) Run the tasks array of functions in parallel, without waiting until the previous function has completed. If any of the functions pass an error to its callback, the main callback...

Why does blocked IO in another thread prevent CreateWindowEx() from returning

windows,multithreading,winapi,io,nonblocking
I have a very simple Windows console application that first creates a thread to process input on stdin. It uses CreateThread() in main() to create the thread, and the first thing the thread does is call getchar() and block, waiting. Then main() registers a window class using RegisterClass() and calls...

Select with non-blocking reads

linux,sockets,select,nonblocking
I'm having a hard time finding an answer for this online. What should be expected when calling select for reading file and the socket is set to non-blocking on Linux ? I don't find it trivial as select man page states: Those listed in readfds will be watched to see...