concurrency

How Clojure's agents compare to Scala's actors?

I wrote a simulation of the Ring network topology in Scala (source here) (Scala 2.8 RC7) and Clojure (source here) (Clojure 1.1) for a comparison of Actors and Agents. While the Scala version shows almost constant message exchange rate as I increase the number of nodes in network from 100 to 1000000, the Clojure version shows message r...

Multithreaded data structure : concurrent stack

Hi all, I'm looking for a C implementation of a concurrent stack (like Cilk THE protocol) that would allow the main thread to push and pop (the pop operation would be at the begining of the stack for example) and a distant thread to pop (this pop operation would be at the end of the stack) with every precaution that has to be taken. If...

Why ThreadGroup is being criticised?

I'm aware of current practice of using Executors instead of ThreadGroup: generally preferred way to deal with Threads catching exceptions from threads, etc... However, what are the inherent flaws of ThreadGroup as such (I've heard a vague criticism for that class)? Thanks for answer. PS. this does not seem to answer this question. ...

A concurrent issue among threads.

Suppose I have a instance variable that has original value: Integer mMyInt = 1; There are two threads. The first changes mMyInt by calling: void setInt() { mMyInt = 2; } The second thread gets mMyInt by calling: Integer getInt() { return mMyInt; } Both threads don't use synchronization. My questions is, what is the possi...

Use case for Future.cancel(false)?

In what situation would one want to pass false for the mayInterruptIfRunning parameter to Future.cancel()? If I understand correctly, if you pass false and the task is cancelled but the thread is not interrupted, the result (or ExecutionException) will never be accessible because the task is still marked as cancelled (i.e. isCancelled()...

Python distutils.Extension : setting a concurrency level

Dear Stackoverflow, I'm wondering how to reproduce the equivalent of a make -j<n> on a setup.py using distutils.Extension, in order to build a C extension to Python 2.6 . My desired outcome: having setup.py build using a few instances of my C-compiler in the same time, instead of only one. There are probably an environnement var or tw...

What is the Thread.State of a thread after Thread.yield() ?

What is the Thread.State of a thread after Thread.yield() ? Is it a Thread.State.WAITING? Thanks. ...

Operating System Implementation of events/signals/wait handles

Out of curiousity I was wondering how Operating Systems implement waking threads that are waiting on events/handles etc. For example say an OS thread continually scans through a list of wait handles and executes the respective threads if necessary. Not that I believe its implemented this way as it would seem inefficient. I think its m...

Why is there no scheduled cached thread pool provided by the Java Executors class?

Executors provides newCachedThreadPool() and newScheduledThreadPool(), but not newCachedScheduledThreadPool(), what gives here? I have an application that receives bursty messages and needs to schedule a fairly lengthy processing step after a fixed delay for each. The time constraints aren't super tight, but I would prefer to have more...

How to call Parallel.ForEach with a multidimensional array

I'm having a little trouble figuring out how to call the Parallel.ForEach with a 2D array of strings: string[,] board = new string[,]{ {"A", "B", "C", "D", "E" }, {"F", "G", "H", "I", "J"}, {"K", "L", "M", "N", "O"}, {"0", "1", "2", "3", "4"}}; Parallel.ForEach(board, row => { for (int i = 0;...

Is it possible for ConcurrentHashMap to "deadlock"?

We have come across a strange issue with ConcurrentHashMap, where two threads appears to be calling put(), and then waiting forever inside the method Unsafe.park(). From the outside, it looks like a deadlock inside ConcurrentHashMap. We have only seen this happen once so far. Can anyone think of anything that could cause these symptoms...

can a worker thread read a control in the GUI?

I got a thread running every few seconds fetching some data from a db but this is based on the selection on a listbox and on a few checkboxes... can I read the values of these controls without using the GUI thread? The data is also read whenever one of the controls change, but the data might change in db without warning...hence the thre...

Is my use of ConcurrentQueue here between 2 threads ok?

Hi, Is my use of ConcurrentQueue here between 2 threads ok? I wanted to check I don't need to "lock" anywhere explicitly. In particular look at the lines where I have in COMMENTS would I drop a packet here... public class PacketCapturer { private static ConcurrentQueue<Packet> _packetQueue = new ConcurrentQueue<Packet>(); public Pa...

Java ThreadPool with poolsize of 1

Does it make sense to use a ThreadPool with a poolsize of just 1 to basically just recycle that one thread over and over again for different uses in the application? Rather then doing new Thread(Runnable()) etc and then letting the garbage collector handle the removal of the thread, I thought it would be more efficient to just use that o...

Access to two variables safely when an interrupt might occur between them.

First of all I'd welcome edits to the title of this question, I couldn't think how to word it better but I'm not too happy with what I came up with. This is a question about concurrency, my application is on a microcontroller in C but I don't think that matters a great deal. I have an interrupt routine which can change the values of tw...

Can two or more queries be executed at the very same time?

Ok, let's say we have bank_account table. There is a row called money. It has 2,000 value. And we have two persons trying to withdraw that money, let's suppose they can do it. So, is it possible that they would do it at the same time? For example. there is a made-up code: $all_money = get_value('money', 'bank_account); //lets suppose t...

Memory barriers vs. interlocked operations

I am trying to improve my understanding of memory barriers. Suppose we have a weak memory model and we adapt Dekker's algorithm. Is it possible to make it work correctly under the weak memory model by adding memory barriers? I think the answer is a surprising no. The reason (if I am correct) is that although a memory barrier can be used...

Is it possible to enforce shared-nothing multithreading at the level of the OS or programming language? (OSX, Objective-C)

I'm trying to implement an actor model of concurrency in Objective-C, because I want to avoid the infamous problems of shared mutable state, locks, semaphores, etc. It can be done, but it takes real discipline to avoid accidentally using shared state. One way to enforce the shared-nothing rule is to use separate processes instead of se...

How to immediately release threads waiting on a BlockingQueue

Consider a BlockingQueue and a few threads waiting on poll(long, TimeUnit) (possibly also on on take()). Now the queue is empty and it is desired to notify the waiting threads that they can stop waiting. The expected behaviour is to have either null returned or the declared InterruptedException thrown. Object.notify() won't work for Li...

is it safe to recv() and send() on one socket concurrently?

I remember having read somewhere that a socket can be regarded as two independent half-duplex channels. Does it mean that recv() and send() of the same socket are actually irrelevant? if so, is it by definition or implementation-specific? if not, how the two interfere with each other? thanks. ...