concurrency

Javascript semaphore / test-and-set / lock?

Is there such a thing as an atomic test-and-set, semaphore, or lock in Javascript? I have javascript invoking async background processes via a custom protocol (the background process literally runs in a separate process, unrelated to the browser). I believe I'm running into a race condition; the background process returns between my tes...

How do I unit test a method containing an asynchronous call?

I have a method that contains an asynchronous call like this: public void MyMethod() { ... (new Action<string>(worker.DoWork)).BeginInvoke(myString, null, null); ... } I'm using Unity and creating mock objects is not a problem, but how can I test that DoWork is called without worrying about race conditions? A previous que...

Best way to control concurrent access to Java collections

Should I use old synchronized Vector collection, ArrayList with synchronized access or Collections.synchronizedList or some other solution for concurrent access? I don't see my question in Related Questions nor in my search (Make your collections thread-safe? isn't the same). Recently, I had to make kind of unit tests on GUI parts of o...

Best practices for multithreaded processing of database records

I have a single process that queries a table for records where PROCESS_IND = 'N', does some processing, and then updates the PROCESS_IND to 'Y'. I'd like to allow for multiple instances of this process to run, but don't know what the best practices are for avoiding concurrency problems. Where should I start? ...

Why this NpgsqlDataAdapter.Update command always return 1?

I want to make my program robust by putting concurrency check, but somehow UpdateCommand fails me even in the most basic update sql. Using Npgsql 2.0.2 var dax = new NpgsqlDataAdapter(); using (var dtStore = delta.Tables["brand"].GetChanges(DataRowState.Modified)) if (dtStore != null) { dax.UpdateCommand = new NpgsqlCommand( @"upda...

Will ConcurrentLinkedQueue#poll() ever block ?

My thread runs forever and calls ConcurrentLinkedQueue#poll() after a ConcurrentLinkedQueue#peek(). But under some conditions, the thread seems to hang. I know this is a bit vague but can people confirm for me that the methods poll() or peek() will NEVER block. Thanks. ...

How do I get two thread to insert specific timestamps into a table?

I created two (or more) threads to insert data in a table in database. When inserting, there is a field CreatedDateTime, that of course, stores the datetime of the record creation. For one case, I want the threads to stay synchronized, so that their CreatedDateTime field will have exactly the same value. When testing with multi threadi...

Why don't large programs (such as games) use loads of different threads?

I don't know how commercial games work inside very much, but the open source games I have come across don't seem to be massively into threading. Same goes for most other desktop applications, normally two or three threads seem to be used (eg program logic and GUI updates). Why don't games have many threads? Eg separate threads for physi...

Django and Sqlite Concurrency issue

I've done a bit of reading related to the concurrency issues with sqlite, but I don't see how they'd apply to Django since it's inherently single threaded. I'm not using any multiprocess modules either. I have absolutely no experience with concurrent programming either, so if someone can identify WHY the following code is causing an Oper...

Why the name "monitor"?

I'm referring to monitors as described here: http://en.wikipedia.org/wiki/Monitor_(synchronization) None of the definitions here seem apropos: http://www.thefreedictionary.com/monitor So why are they called that? == Update == Thank you for the answers, everyone! I guess I was confused because I don't think of monitors usually as a...

synchronized block vs synchronized method?

Can any one tell me the advantage of synchronized method over synchronized block with an example?Thanks. ...

How to show source line numbers in jstack output ?

This is a jstack output from a running JVM "FooThread" prio=10 tid=0x00007f159c2ca000 nid=0x6e21 waiting on condition ..snipped java.lang.Thread.State: TIMED_WAITING (sleeping) at java.lang.Thread.sleep(Native Method) at com.myco.impl.QueueFooThread.run(Unknown Source) I want the line number in QueueFooThread to show up l...

Need help with designing "infinite" threads.

I have some database table and need to process records from it 5 at a time as long as app is running. So, it looks like this: Get a record that hasn't been processed yet or not processing now by other threads. Process it (this is a long process that depends on internet connection so it could timeout/throw errors). Move to the next reco...

What's the fastest way to make concurrent web requests in Perl?

I need to make some concurrent XML feed requests in Perl. What is the fastest way to do this? ...

WCF InstanceContextMode.Multiple issues

So I'm hosting WCF service in a WinForms application. I have the following [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.PerCall)] public class Test : ITest { public string TestIt(string input) { Thread.Sleep(5000); return "test"; } } I'm ...

In C# 2.0+, is it necessary to lock around a closure that another thread will execute?

In C# 2.0+, is it necessary to lock around a closure that another thread will execute? Specifically, in the example below, is the locking necessary to ensure that the Maint thread flushes its value of x to shared memory and that thread t reads its value of x from shared memory? I think it is, but if I'm wrong, please reference e.g. an ...

Concurrency question about program running in OS

Here is what I know about concurrency in OS. In order to run multi-task in an OS, the CPU will allocate a time slot to each task. When doing task A, other task will "sleep" and so on. Here is my question: I have a timer program that count for inactivity of keyboard / mouse. If inactivity continues within 15min, a screen saver program ...

Tips of coding java programs in multicore scenario

There seems to be a lot of fuss about multicore and java. While some people say that java support is not good enough, it definitely seems to be an area to look forward to. There seems to be many techniques to improve performance of concurrent programs. Any tips/advices about programming in a multi core scenario is appreciated. ...

ConcurrentModificationException and a HashMap

I am persisting objects using JPA. The Main object has an owning One-Many relationship with another object. The other object is stored in a HashMap. What sort of synchronization would fix this problem? It seems to happen at completely random times and is very unpredictable. Here is the exception I get: Exception in thread "pool-1-t...

Java Threading Tutorial Type Question

I am fairly naive when it comes to the world of Java Threading and Concurrency. I am currently trying to learn. I made a simple example to try to figure out how concurrency works. Here is my code: import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class ThreadedService { private ExecutorS...