concurrency

implementing remove on a ConcurrentMultimap without races

I've been looking at the problem of writing a concurrent Multimap, and I have an implementation backed by the Google Guava AbstractSetMultimap and a MapMaker computing map that creates on demand the values-collections as a set view over a ConcurrentHashMap. With some care over the view collections and various wrappers, I think this gets ...

Linq to SQL concurrency problem

Hallo, I have web service that has multiple methods that can be called. Each time one of these methods is called I am logging the call to a statistics database so we know how many times each method is called each month and the average process time. Each time I log statistic data I first check the database to see if that method for the ...

Making threads wait

I have a bit of a problem. I have a java application and when it starts it needs to make around six maybe seven threads that just wait for some sort of event to occur (i.e. user presses a button). An example of how I make these threads is below. The problem is, I open my task manager only to see that all my four cpu cores are at 100% (up...

"Refreshing" a fixed size thread pool when using for a ExecutorService

In my application, I use ExecutorService a lot for making async calls. ExecutorService executorService = Executors.newFixedThreadPool(10); And I shutdown the executorService only when the app (web based) shuts down. Recently when debugging some issues I was looking through this code and wondering whether there can be cases during the...

Waiting for Variable Change

Here my code snippet written in Qt. bool myFunc() { ....... while(!tcpCommunicator->isLoginReplyExist) { qApp->processEvents(QEventLoop::AllEvents); } ....... return tcpCommunicator->res; } After "isLoginReplyExist" is changed by another part of program I want to exit from loop, is there any better way to ...

Whats the uses of AtomicReferenceArray

I want to see example, when would it be good idea to use AtomicReferenceArray. ...

Does this seem like a reasonable approach to a concurrent set/queue combo?

Update: As Brian pointed out, my original idea did indeed have a concurrency issue. This was somewhat obscured by the signature of the ConcurrentDictionary<TKey, TValue>.AddOrUpdate method, which can lull a lazy thinker (like myself) into believing that everything--the set add as well as the queue push--will somehow happen all at once, a...

Is Spring's ThreadPoolTaskExecutor blocking something?

We are using the ThreadPoolTaskExecutor within Spring (inside of Tomcat) to launch a concurrent server which listens on a port (3001). Our code looks a bit like: .... ServerSocket listener = new ServerSocket(port); Socket server; while (true) { PollingTask pollingTask; server = ...

Determining synchronization scope?

Hi, in trying to improve my understanding on concurrency issues, I am looking at the following scenario (Edit: I've changed the example from List to Runtime, which is closer to what I am trying): public class Example { private final Object lock = new Object(); private final Runtime runtime = Runtime.getRuntime(); public void...

What could be causing a deadlock or otherwise causing this concurrency test to inconsistently fail?

I've been fiddling around with CHESS, which seems like an incredibly useful tool. However, ironically, I seem to be dealing with a Heisenbug in one of my test methods. The results reported by CHESS when I run this test are unpredictable: Sometimes the test will pass Sometimes the test will fail, with no further description (simply: "Te...

how to call a method immediately after thread run() ends?

Hi to all, i want to call a method that returns a string value. Actually this string value is an instance variable, and run method put the value of the string. So, i want to call a method to get the string value updated by thread run() method.. How i do it...? Plz anyone help me.. Saravanan ...

synchronization in java

Will following 2 code block achieve the same result. What is the difference better then, if any? class test { Object obj = new Object(); void test(){ synchronized(obj){ } } void test1(){ synchronized(this){ } } } ...

Is LockModeType.PESSIMISTIC_WRITE sufficient for an UPSERT in JPA?

I've read this article on JPA concurrency, but either I am too thick or it is not explicit enough. I am looking to do a database-controlled atomic update-if-found-else-insert operation (an UPSERT). It looks to my poor slow brain that I can--within a transaction of course--run a named query with a lock mode of PESSIMISTIC_WRITE, see if ...

Python - what is the accepted money calculation technique?

Take the following example: >>> from decimal import Decimal >>> nrml_price = Decimal('0.59') >>> discounted = nrml_price / 3 # Taking 2/3 off the price with a coupon Decimal('0.1966666666666666666666666667') # Customers don't have fractions of a penny >>> (nrml_price / 3).quantize(D('0.00')) # So I quantize to get 2 decimal places De...

Do stored procedures lock tables/rows?

Quite a simple question. In SQL 2008 if I have a stored procedure (see below) do I run the risk of a race condition between the first two statements or does the stored procedure put a lock on the things it touches like transactions do? ALTER PROCEDURE [dbo].[usp_SetAssignedTo] -- Add the parameters for the stored procedure here ...

Semaphores and concurrent programming

Hello. For a homework assignment i need to program the following scenario. This is going to be done using semaphores using BACI (which is C--) There are 2 unisex restrooms that can hold 4 people each. Since it is unisex only people of the same sex can be in the restroom at the same time and FIFO is not important. I have the basic "al...

What does C++ Graph mean in Intel Concurrent Collections?

Hi, I am reading the user guide that came with Intel concurrent collections, and I don't understand what they mean by the following sentence [Page 4 Section 1.1]: You define an Intel Concurrent Collections for C++ graph which specifies the following: Anybody know what do they mean by C++ Graph? ...

Multi-threaded Java server vs safe publication

When you google for multi-threaded java server, most of the time you'll get a solution based on a following pattern: public class MultiThreadServer implements Runnable { private Socket socket; MultiThreadServer(Socket socket) { this.socket = socket; } public static void main(String args[]) throws Exception { ServerSock...

How can two concurrent threads or processes communicate?

Broadly, how does inter-process and inter-thread communication work? Clarification: I understand this question can't be exhaustively answered in one succinct paragraph. I'm looking for answers that will be a good starting point for beginners - high level concepts of how it works. ...

BGL concurrent read accesses problem

I need to iterate over the vertices and edges of a BGL adjacency_list from several threads. Which would be an efficient way to do that, provided that the graph is large (mutex..)? The BGL methods don't support reentrant calls? ...