concurrency

Java Concurrency JDK 1.6: Busy wait does better than signalling? Effective Java #51

Joshua Bloch's "Effective Java", Item 51 is not about depending on the thread scheduler as well as not keeping threads unnecessarily in the runnable state. Quoted text: The main technique for keeping the number of runnable threads down is to have each thread do a small amount of work and then wait for some condition using Object.w...

Any practical example of LockSupport & AbstractQueuedSynchronizer use?

Guys, can anyone give a simple practical example of LockSupport & AbstractQueuedSynchronizer use? Example given in javadocs is quite strained. Usage of Semaphore permits is understood by me. Thanks for any response. ...

Why do threads share the heap space?

Threads each have their own stack, but they share a common heap. Its clear to everyone that stack is for local/method variables & heap is for instance/class variables. What is the benefit of sharing heap among threads. There are several number of threads running simultaneously, so sharing memory can lead to issues such as concurrent m...

Processes, threads, green threads, protothreads, fibers, coroutines: what's the difference?

I'm reading up on concurrency. I've got a bit over my head with terms that have confusingly similar definitions. Namely: Processes Threads "Green threads" Protothreads Fibers Coroutines "Goroutines" in the Go language My impression is that the distinctions rest on (1) whether truly parallel or multiplexed; (2) whether managed at th...

How is "become" implemented in languages that support the actor model?

The actor model is nicely described by Gul Agha on his technical report, "Actors: a model of concurrent computation in distributed systems". On page 49 he explains the "become" command: become <expression> After calling "become X", an actor will forward all his messages to another actor's mailbox (X). I'm not sure, however, how this...

Multithreaded drawing in .NET?

(Edit: to clarify, my main goal is concurrency, but not necessarily for multi-core machines) I'm fairly new to all concepts on concurrency, but I figured out I needed to have parallel drawing routines, for a number of reasons: I wanted to draw different portions of a graphic separatedly (background refreshed less often than foreground...

Java: Does LinkedBlockingQueue take into account order of consumers?

I have 3 threads: 2 consumers, ConsumerA and ConsumerB, and a Producer. I also have a LinkedBlockingQueue queue At t=1: ConsumerA calls queue.take() At t=2: ConsumerB calls queue.take() At t=3: Producer calls queue.put(foo) Is it guaranteed that ConsumerA receives foo before ConsumerB? In other words, the order in which the consumer...

Possible to simulate the mySQL functionality ON DUPLICATE KEY UPDATE with SQL Server

I am using SQL Server 2008, and would like to be able to take advantage of something like mySQL's ON DUPLICATE KEY UPDATE clause for INSERT statements Current legacy code does a delete and subsequent insert that is running into concurrency issues with duplicate key inserts from separate threads: Here is the error I see in my production...

Atomically incrementing counters stored in ConcurrentHashMap

I would like to collect some metrics from various places in a web app. To keep it simple, all these will be counters and therefore the only modifier operation is to increment them by 1. The increments will be concurrent and often. The reads (dumping the stats) is a rare operation. I was thinking to use a ConcurrentHashMap. The issue i...

run php script concurrently

I'm trying to use a script to process a lot of dta records, let's name it process.php, the problem is that I have a huge data set, to make the job done faster, I want to run multiple instances of this script with /usr/bin/php process.php start_record end_record & so I'll have them running in parallel like /usr/bin/php process...

Multiple threads vs single thread.

I am working on a server client application right now (just for learning purposes), and am trying to get information to make a design decision regarding threads in this application. Currently i have one thread in charge of all nonblocking io with the clients. When it receives any data, it sends it off to a worker thread that creates an ...

Duplicate key-value pairs returned by memcached

hi - We are using a cluster of memcached servers for caching purpose, in a Django(Python) production, having tried both cmemcache and python-memcache as the API. The problem is under high concurrency, we started to have duplicate key-value pairs, that is to say we are having multi values for a single key. Is there anyone having had the s...

Insert Queries Can Only Cause Concurrency Issues With Select Queries?

This is just for my own understanding of how concurrency issues work. Let's say I have an insert statement that runs at the same time as a select query. If the insert statement occurs while the select query is still running, will the select query show a conflict because the number of rows to select has changed? Or is it that concurrenc...

Which Actor model library/framework for Java?

There are so many different Actor model implementations for Java (and the JVM languages). A lot of Actor libraries and frameworks have been implemented to permit Actor-style programming in Java (which doesn't have Actors built-in). I think the Actor model has big advantages, but the choices for Java are overwhelming! Can someone post t...

Is AsyncTask really massively flawed or am I just missing something?

I have investigated this problem for months now, came up with different solutions to it, which I am not happy with since they are all massive hacks. I still cannot believe that a class that flawed in design made it into the framework and no-one is talking about it, so I guess I just must be missing something. The problem is with AsyncTa...

Code Golf: The Unisex Restroom Simulation

Background The unisex restroom problem is a classical synchronization problem in computer science. The general class of problems that this simulates is as follows: If you have k types of threads that need to execute tasks using n shared resources, and at any time only one thread type may be using the resources, then it's a generalizati...

Unit testing concurrent software - what do you do?

As software gets more and more concurrent, how do you handle testing the core behaviour of the type with your unit tests (not the parallel behaviour, just the core behaviour)? In the good old days, you had a type, you called it, and you checked either what it returned and/or what other things it called. Nowadays, you call a method and ...

Thread.Abort and alternatives

This is more out of personal curiosity/interest than a specific problem I'm trying to solve. Suppose you have a program that is performing some operation on user-supplied information (such as a search string) that changes as the user types it. Suppose that you want to show the user the most relevant information for what they've typed at...

Java: Is `while (true) { ... }` loop in a thread bad? What's the alternative?

Is while (true) { ... } loop in threads bad? What's the alternative? Update; what I'm trying to to... I have ~10,000 threads, each consuming messages from their private queues. I have one thread that's producing messages one by one and putting them in the correct consumer's queue. Each consumer thread loops indefinitely, checking for a...

Managing concurrent reads from a single Socket in a .Net application

I am writing a multi-threaded .Net application in which many callers need to concurrently read from a single Socket. Data read from the socket is split into records / chunks of data - each record is targetted at a specific caller identified by a CallerID in the header, so for example the stream of bytes read from the socket might be som...