Questions tagged [concurrent-programming]

[CONCURRENT] programming refers to software paradigms where system-design allows multiple actions to be executed one independently of any other, while system resources become available, without any additional constraints (as opposed to a strictly [PARALLEL] type of system-design)

[CONCURRENT] programming refers to a system design paradigm, where multiple actions may be scheduled to execution at any time and if more resources are available, some may happen to become executed simultaneously.

A concurrent run of a code-execution happens simultaneously (just by coincidence),
using more than one CPU or processor core
and other shared resources to execute a program
or multiple (but mutually independent)
computational units (tasks, threads, et al).

With this said, the option for them to interact with each other exists, but requires additional steps and measures so as to avoid their one-side lock inefficiencies, plus a risk of a mutual locking.

Usually, concurrent programming has to provide additional validation of correctness and robustness against uncoordinated processing units' failures, deadlocking et al, while it may -- just by a weak-coincidence -- benefit from a better resources usage (higher occupancy rate than with just a [SERIAL] arrangement of execution), which, with respect to the need of algorithmically assure the set former robustness goals, does not assure an end-to-end performance of the concurrent processing scales linearly with an amount of resources available (ref. below - non-linear expansion of resource arbitration overheads).

Usually, concurrent programming involves control over shared resources, which is achieved by implementing "arbiters" that handle the access to those resources and distribute the resources among all processes/threads.


A professional & principal disambiguation between [PARALLEL] vs. [CONCURRENT] is needed, as true parallel code-execution requires much more than just having a few cores and a fan-out of a horde of (uncoordinated) threads, hunting for time-sharing access to a pool of system-reserved resources. Concurrent execution is simply by far not a parallel-processing


A good Rob Pike's speech on common misunderstanding on this subject

232 questions
132
votes
8 answers

Is there a Mutex in Java?

Is there a Mutex object in java or a way to create one? I am asking because a Semaphore object initialized with 1 permit does not help me. Think of this case: try { semaphore.acquire(); //do stuff semaphore.release(); } catch (Exception e)…
Noam Nevo
  • 3,021
  • 10
  • 35
  • 49
93
votes
4 answers

Java 8: Parallel FOR loop

I have heard Java 8 provides a lot of utilities regarding concurrent computing. Therefore I am wondering what is the simplest way to parallelise the given for loop? public static void main(String[] args) { Set servers = getServers(); …
81
votes
7 answers

How to have 2 JVMs talk to one another

I have the following situation: I have 2 JVM processes (really 2 java processes running separately, not 2 threads) running on a local machine. Let's call them ProcessA an ProcessB. I want them to communicate (exchange data) with one another (e.g.…
tnk_peka
  • 1,525
  • 2
  • 15
  • 25
45
votes
3 answers

Is parallel programming == multithread programming?

Is parallel programming == multithread programming?
45
votes
2 answers

Is this the proper way to iterate over Concurrentdictionary in C#

I'm only using this code for an example. Assume I have the following Person class. using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace dictionaryDisplay { class Person { public string FirstName { get;…
Charles Whitfield
  • 477
  • 1
  • 4
  • 7
39
votes
5 answers

Java: reference escape

Read that the following code is an example of "unsafe construction" as it allows this reference to escape. I couldn't quite get how 'this' escapes. I am pretty new to the java world. Can any one help me understand this. public class ThisEscape { …
softwarematter
  • 28,015
  • 64
  • 169
  • 263
32
votes
15 answers

How to explain the "deadlock" better?

I am struggling to explain "deadlock" in threads in easy words, so please help. What could be the best example of "deadlock" (say, in Java), and how it does happen in steps and how to prevent it? But without getting into details too deep. I know…
alexeypro
  • 3,633
  • 7
  • 36
  • 49
27
votes
2 answers

How to stop the execution of Executor ThreadPool in java?

I am working on the Executors in java to concurrently run more threads at a time. I have a set of Runnable Objects and i assign it to the Exceutors.The Executor is working fine and every thing is fine.But after all the tasks are executed in the pool…
Rajapandian
  • 9,257
  • 24
  • 74
  • 86
20
votes
1 answer

Java blocking issue: Why would JVM block threads in many different classes/methods?

Update: This looks like a memory issue. A 3.8 Gb Hprof file indicated that the JVM was dumping-its-heap when this "blocking" occurred. Our operations team saw that the site wasn't responding, took a stack trace, then shut down the instance. I…
user331465
  • 2,984
  • 13
  • 47
  • 77
19
votes
3 answers

What's the difference of the usage of volatile between C/C++ and C#/Java?

I found it in many references which mention that volatile in C/C++ is is weak and may cause issue in concurrent environment on multiple processor, but it (volatile) can be used as communication mechanism between difference CPUs in C#/Java. It seems…
Thomson
  • 20,586
  • 28
  • 90
  • 134
16
votes
4 answers

Java Framework for managing Tasks

my question is, whether there exists a framework in Java for managing and concurrently running Tasks that have logical dependencies. My Task is as follows: I have a lot of independent tasks (Let's say A,B,C,D...), They are implemented as Commands…
Mark Bramnik
  • 39,963
  • 4
  • 57
  • 97
16
votes
4 answers

STL algorithms and concurrent programming

Can any of STL algorithms/container operations like std::fill, std::transform be executed in parallel if I enable OpenMP for my compiler? I am working with MSVC 2008 at the moment. Or maybe there are other ways to make it concurrent? Thanks.
Andrew
  • 2,309
  • 4
  • 27
  • 42
16
votes
9 answers

Why Clojure instead of Java for concurrent programming

When Java is providing the capabilities for concurrent programming, what are the major advantages in using Clojure (instead of Java)?
John Jesudason
  • 161
  • 1
  • 3
14
votes
5 answers

What is the reason why high level abstractions that use lock free programming deep down aren't popular?

From what I gathered on the lock free programming, it is incredibly hard to do right... and I agree. Just thinking about some problems makes my head hurt. But what I wonder is, why isn't there a widespread use of high-level wrappers around (e.g.…
NoSenseEtAl
  • 28,205
  • 28
  • 128
  • 277
13
votes
5 answers

Sorting a ConcurrentDictionary by Value

I am able to sort my ConcurrentDictionary by value like so: static ConcurrentDictionary Proxies = new ConcurrentDictionary(); Proxies.OrderBy(p => p.Value.Speed); Which is great, except I want to set that new…
1
2 3
15 16