157

Because "multiple concurrent writes" is much, much harder to accomplish in the core database engine than single-writer, multiple-reader. It's beyond SQLite's design parameters, and including it would likely subvert SQLite's delightfully small size and simplicity. Supporting high degrees of write concurrency is a hallmark of large database engines such as ...


107

A Fiber is a lightweight thread that uses cooperative multitasking instead of preemptive multitasking. A running fiber must explicitly "yield" to allow another fiber to run, which makes their implementation much easier than kernel or user threads. A Coroutine is a component that generalizes a subroutine to allow multiple entry points for suspending and ...


99

Concurrency and parallelism are two related but distinct concepts. Concurrency means, essentially, that task A and task B both need to happen independently of each other, and A starts running, and then B starts before A is finished. There are various different ways of accomplishing concurrency. One of them is parallelism--having multiple CPUs working on ...


72

It is deprecated as a general technique, because - as you noticed - creation and destruction of short lived objects per se (i.e. memory allocation and GC) is extremely cheap in modern JVMs. So using a hand-written object pool for your run-of-the-mill objects is most likely slower, more complicated and more error-prone than plain new.* It still has its uses ...


67

I'm only a casual Go user, so take the following with a grain of salt. Wikipedia defines green threads as "threads that are scheduled by a virtual machine (VM) instead of natively by the underlying operating system". Green threads emulate multithreaded environments without relying on any native OS capabilities, and they are managed in user space instead of ...


60

Don't get fancy, just toss a simple (threadsafe) counter behind some communication endpoint (WCF, web service, whatever): long x = long.MinValue; public long ID(){ return Interlocked.Increment(ref x); } Yes, it will eventually overflow. Yes, it doesn't handle reboots. Yes, it's not random. Yes, someone could run this on multiple servers. ...


38

The two concepts are related, but different. Concurrency means that two or more calculations happen within the same time frame, and there is usually some sort of dependency between them. Parallelism means that two or more calculations happen simultaneously. Put boldly, concurrency describes a problem (two things need to happen together), while parallelism ...


36

The answer to the concrete question: 'Is object pooling a deprecated technique?' is: No. Object pooling is widely used in specific places - thread pooling, database connection pooling etc. General object creation has never been a slow process. Pooling in itself consumes resources - memory and processing power. Any optimization is a trade-off. The rule is: ...


36

Is it impossible, or just plain unlikely? Impossible. It can be implemented in different ways, e.g., via the Compare-and-swap where the hardware guarantees sequential execution. It can get a bit complicated in presence of multiple cores or even multiple sockets and needs a complicated protocol between the cores, but this is all taken care of.


34

You have multiple cores/procesors, use them Async is best for doing heavy IO bound processing but what about heavy CPU bound processing? The problem arises when single-threaded code blocks (ie gets stuck) on a long-running process. For instance, remember back when printing a word processor document would make the whole application freeze until the job was ...


33

You almost certainly should look at Clojure - in my opinion it's the best modern language for multi-core programming and it is extremely productive. Key attributes: It's a functional language, which is a boon for both concurrency and your ability to develop using higher level abstractions. It features fully immutable persistent data structures and lazy ...


32

Here's a quick and easy motivation: If you want to code for anything but the smallest, weakest systems, you will be writing concurrent code. Want to write for the cloud? Compute instances in the cloud are small. You don't get big ones, you get lots of small ones. Suddenly your little web app is a concurrent app. If you designed it well, you can just toss in ...


29

I remember the JVM abandoning green threads and moving to native threads. This was for two simple reasons: the green threads were frankly rubbish, and there was a need to support multi-core processors with the limited developer effort available at Sun. This was a shame - green threads provide a far better abstraction, allowing concurrency to be a useful ...


28

Good concurrency requires a lot more than throwing a few threads in an application and hoping for the best. There's a range in how concurrent a program can be going from embarrassingly parallel to pure sequential. Any given program can use Amdahl's law to express how scalable a problem or algorithm is. A couple qualifications for a embarrassingly parallel ...


28

Major operating systems are mature enough to know how to handle processes which use every available core. Other processes may (and often will) be affected, but the computation won't become slower because you used every available core. The choice of the number of cores depends more on your intention of doing something else while the calculation is being ...


27

The classic method to do this is to use a transactional database (so there's no clashes) and to do a tentative allocation of the seat to you that expires after some length of time (e.g., 10 minutes for kiosks) that gives you enough time to pay. If the (customer-visible) transaction falls through or times out, the seat allocation can be released back into the ...


27

You could try D. It offers three models. I recommend either the first or second. std.concurrency. If you use this module for all your concurrency needs, then a combination of the language and the standard library enforces isolation between threads. Threads primarily communicate via message passing, with limited support for shared memory in a way that ...


27

The latest rage in academic circles seems to be Software Transactional Memory (STM) and it promises to take all the hairy details of multi-threaded programming out of the hands of the programmers by using sufficiently smart compiler technology. Behind the scenes it is still locks and semaphores but you as the programmer don't have to worry about it. The ...


25

You are looking for the File Locking And Concurrency documentation. SQLite processes use a series of locks to handle concurrency; to read, several processes can obtain a SHARED lock. A process that writes, will need to obtain a RESERVED lock, and only when actually having to flush changes to disk does it move to the PENDING state. Any reading process will ...


25

If I were asked that question, and they made it clear that it has to be unique across reboots and across different machines, I'd give them a function that calls into the standard mechanism for creating a new GUID, whatever that happens to be in the language being used.


25

Coroutines never left, they were just overshadowed by other things in the meanwhile. The recently increased interest in asynchronous programming and therefore coroutines is largely due to three factors: increased acceptance of functional programming techniques, toolsets with poor support for true parallelism (JavaScript! Python!), and most importantly: the ...


23

Take a look at Microsoft's Parallel Programming for .net. It is very intuitive. Many personal computers and workstations have two or four cores (that is, CPUs) that enable multiple threads to be executed simultaneously. Computers in the near future are expected to have significantly more cores. To take advantage of the hardware of today and tomorrow, you ...


23

Erlang is definitely a great option, but something a little more practical might be Go, Google's new language. It's not so far from other common languages, so it's typically easy to get if you already know other 'easy' languages. Many people compare it with Python or even Lua in terms of how 'comfortable' is it to program.


23

Yes, but it depends. You can’t expect to write nontrivial, high-performance software without both taking advantage of parallel hardware and using concurrency as a program structuring technique. But most software is both trivial and non–performance-critical. A web app isn’t doing much number crunching, and CRUD apps have nothing like the hard timing limits ...


22

The interviewer said the method will be called concurrently, not in parallel; just return the date/time down to as many decimal places as you can. Why is everyone over-thinking this? You'll be dead a long time before any finiteness is expended and you don't have a chance of a collision. If you're worried about it returning the same time, add a delay for ...


21

From 1970 to about 2002 processors doubled in speed about every 18 months. So as a programmer all you had to do was wait and your program would go faster. The problem is that around 2002 the rules changed. Now they are not making bigger fast processors they are making smaller slower processors but putting them out in groups. The computer I am working on now ...


Only top voted, non community-wiki answers of a minimum length are eligible