Questions tagged [blocking]

Blocking mode I/O blocks the issuing thread until the operation transfers at least one byte or an error or end of stream occurs. Blocking algorithms refer to an operation in multithreaded environment which temporarily restricts access to some resources to a single thread, thus blocking all other ones. It isn't clear which this tag is intended for.

1679 questions
17
votes
3 answers

Is an OutputStream in Java blocking? (Sockets)

I am currently writing naive network code for a project and a mate hinted me at the possibility that when I send a package of information from the server to all clients in an iterative fashion I might get intense lag when one of the clients is not…
salbeira
  • 2,375
  • 5
  • 26
  • 40
16
votes
6 answers

How to achieve lock-free, but blocking behavior?

I'm implementing a lock-free single producer single consumer queue for an intensive network application. I have a bunch of worker threads receiving work in their own separate queues, which they then dequeue and process. Removing the locks from these…
haste
  • 1,441
  • 1
  • 10
  • 21
16
votes
3 answers

How to reset a socket back to blocking mode (after I set it to nonblocking mode)?

I have read this regarding setting a socket to non-blocking mode. http://www.gnu.org/software/libc/manual/html_mono/libc.html#File-Status-Flags Here is what I did: static void setnonblocking(int sock) { int opts; opts =…
n179911
  • 19,547
  • 46
  • 120
  • 162
16
votes
1 answer

Does JavaScript WebSocket.send method block?

If I'm sending a large Blob or ArrayBuffer over a JavaScript WebSocket via its send method... does the send method call block until the data is sent, or does it make a copy of the data to send asynchronously so the call can return immediately? A…
Triynko
  • 18,766
  • 21
  • 107
  • 173
16
votes
1 answer

If nodejs uses non blocking IO, how is fs.readFileSync implemented?

I see a lot of synchronous functions in the file system library. such as fs.readFileSync(filename, [options]). How (and why) are these functions implemented if node has async/non-blocking IO and no sleep method - and can I use the same mechanism to…
guy mograbi
  • 27,391
  • 16
  • 83
  • 122
15
votes
5 answers

How to block a mobile number call and message receiving in android application development?

I would like to implement an application for block a mobile number for receiving or sending calls and messages. In my application I am entering mobile number at EditText box then I am clicking a button for block the mobile number which has entered…
prasad.gai
  • 2,977
  • 10
  • 58
  • 93
15
votes
6 answers

sleep() in Javascript

Suppose I want to block Javascript execution for certain time for some weird reason, how can I do that. There is no sleep() in JS. Pls don't say do a while() loop because that's bad. I can do a window.showModalDialog and put a window.close in the…
nomind
  • 303
  • 1
  • 2
  • 8
15
votes
3 answers

Linux, cancel blocking read()

In a multi-threaded Linux program used for serial communication, is it possible (and what would be the best approach) to terminate a blocking read() call from another thread? I would like to keep everything as reactive as possible and avoid any use…
Jakob Odersky
  • 1,371
  • 11
  • 23
15
votes
3 answers

When should a method throw InterruptedException, and how should I handle one that does? (blocking method)

If a method must be a blocking method, am I right in thinking that if I leave out throws InterruptedException, I have made a mistake? In a nutshell: A blocking method should include throws InterruptedException otherwise is a normal method. A…
9628001
  • 509
  • 1
  • 4
  • 11
14
votes
4 answers

Dns.BeginGetHost... methods blocking

So I want to make a lot of DNS queries. I create (thousands) of Tasks from the Begin/EndGetHostEntry async pair: var lookupTask = Task.Factory.FromAsync ( Dns.BeginGetHostEntry, (Func) Dns.EndGetHostEntry, …
spender
  • 117,338
  • 33
  • 229
  • 351
13
votes
4 answers

Is there a way to get all IP addresses of YouTube to block it with Windows Firewall?

I want to programme my own anti-distraction tool. I can not / do not want to use the hosts file or third-party apps. When using IPsec or Windows Firewall, it only accepts IP addresses. There is youtube.[264 TLD] www.youtube.[264 TLD]…
user670186
  • 2,588
  • 6
  • 37
  • 55
13
votes
4 answers

Do we need to use MappedByteBuffer.force() to flush data to disk?

I am using MappedByteBuffer to speed up file read/write operations(). My questions as below: I am not sure if I need to use .force() method to flush the content to disk or not. It seems like without .force(), the .getInt() can still work perfectly…
janetsmith
  • 8,562
  • 11
  • 58
  • 76
13
votes
3 answers

How to see if a pipe is empty

Assuming a pipe, int pipe_fd[2]; pipe(pipe_fd); We fork, and expect that one process will write into the pipe at an arbitrary time. In one of the processes, we want to be able to check the contents of the pipe without blocking. i.e. While a…
darkpbj
  • 2,892
  • 4
  • 22
  • 32
13
votes
2 answers

If MessageBox()/related are synchronous, why doesn't my message loop freeze?

Why is it that if I call a seemingly synchronous Windows function like MessageBox() inside of my message loop, the loop itself doesn't freeze as if I called Sleep() (or a similar function) instead? To illustrate my point, take the following skeletal…
GRB
12
votes
2 answers

Why is "Multiplexed, non-blocking I/O, [..] much more scalable than thread-oriented, blocking I/O"?

I'm reading about Channels in the JDK 7 docs (here), and stumbled upon this: Multiplexed, non-blocking I/O, which is much more scalable than thread-oriented, blocking I/O, [...] Is there a simple explanation as to why this is so?
Mads Nielsen
  • 634
  • 5
  • 16