Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [concurrency]

Concurrency is a property of systems in which several processes are executing at the same time.

2
votes
3answers
175 views

Why datatypes are marked as thread-safe instead of procedures?

In Rust, Send (or Sync) marker traits are used to indicate whether a value of a type (or a reference to that) can be worked on within threaded context. However, it is an attribute of a function or a ...
0
votes
0answers
21 views

Actor Model In Java Using CompletableFuture and Executors

I am planning to implement an Event Driven system, based on the Actor model using CompletableFutures and individual Thread Pools for each actor. However my tasks are completely sequential in nature ...
1
vote
0answers
38 views

What is a message in relation to javascript's message queue in its event loop?

I'm learning about javascript's event loop, however I'm not understanding what a message is? The resources I find mention how the callback associated with events get added to the message queue, but ...
1
vote
1answer
24 views

How does Operational Transformations work when offering offline editing capabilities?

As far as I understand, OT works really well with concurrent editing. There is only one remote copy of the document, and all editors update that remote copy simultaneously. There is a concept of lag ...
0
votes
2answers
92 views

Design optimal read operation in my service

---- Description I'd like to optimize read operation in my service. It has basically put and get methods. On put I accept some numbers in a string format and put them into thread-safe cache with ...
1
vote
2answers
87 views

Approaches to dynamically determining if concurrency needed

There is a series of procedures, each of which falls into one of two general categories. Most of these are of category 1: it would be best to execute them one at a time - the overhead associated with ...
-3
votes
3answers
136 views

Real-world analogy for green threads

I'm giving a talk on concurrency which will cover multithreading, multiprocessing and green threads. I'd like to give simple real-world analogies of single threaded programs, multithreading, ...
1
vote
1answer
91 views

Queueing API requests

Is it a good practice at all? E.g. we have an API layer which has to call some service when it receives a request, and the work which that service has to do must not be done concurrently. If there ...
3
votes
1answer
93 views

Design of file I/O -> processing -> file I/O system

I'm in the process of designing a new desktop application which is very different from other stuff I did before, and so I'll be happy if I could be pointed towards the right direction regarding the ...
0
votes
1answer
34 views

Service lifecycle with non blocking start and stop

So the basic scenario is I have a class that starts/stops service objects with the methods start(String serviceid)/stop(String serviceid). It is designed to then forward various execution tasks to the ...
0
votes
1answer
34 views

How state updates to existing instances/sessions are generally done?

This is a very broad question, but maybe someone has a worthwhile response. There is a general synchronization issue that often has to be solved, but always seems to be difficult. Here's an example: ...
3
votes
1answer
175 views

Is a race condition with no downside still a race condition?

I am writing a piece of code which takes the difference between two numbers, finds that location in memory, and then sets the location to true. Currently my method of performing this is as follows. ...
1
vote
0answers
35 views

UML how to model parallel activity with runtime-dependent number of participants

I want to model an activity that involves processing several items in parallel. So to speak, I want to find a Activity Diagram representation for something like the following snippet / pseudocode: ...
5
votes
0answers
274 views

Concurrent fault-safe data structure

I am building an application that aims to process ~10M data items per second. Each item is exactly 42 bytes small (including a sorting key) which means the total data rate will not be big 420 MB/s. ...
10
votes
4answers
2k views

What should I do when optimistic locking doesn't work?

I have this following scenario: A user makes a GET request to /projects/1 and receives an ETag. The user makes a PUT request to /projects/1 with the ETag from step #1. The user makes another PUT ...
2
votes
2answers
323 views

How to handle “Optimistic Locking” on a collection with ETag headers?

Consider endpoint /projects that returns a list of projects with the following headers: HTTP/1.1 200 OK Etag: "superEtag" The etag value represents a hash of the entire collection and it does not ...
-1
votes
1answer
169 views

Is there a race condition for multiple threads on multiple cores trying to lock a global variable?

I understand in a single core system, multiple threads operate in sequence, scheduled by the OS. Hence it can't be possible to have a race condition since by definition they are taking turns locking a ...
3
votes
2answers
304 views

How to handle concurrent updates for the same record in a distributed system

I'm trying to figure out the best solution for the below. Any help would be great. So basically I have a service (that can be scaled horizontally), which listens on a queue. Every message received ...
-2
votes
1answer
156 views

Shopping Cart Concurrency Question [closed]

I have a problem with my e-commerce site. There can be multiple simultaneous requests to add items in the shopping cart, I was moving towards the design where when an item is added to the shopping ...
2
votes
1answer
626 views

How would you design a “multithreaded” LRU cache using C++ (unordered_map and Linkedlist)?

Please note that this is about a thread-safe LRU cache (not simply a LRU cache as specified in https://leetcode.com/problems/lru-cache/description/). It isn't a duplicate of LRU cache design question ...
1
vote
1answer
107 views

Inventory management with limited time hold strategy - How do I protect from bad actors?

Some sites, like theater ticket reservations, place a limited-time hold on the item , while the order is being processed. As soon as you select the seat and proceed to pay, Seat is reserved say for 10 ...
2
votes
1answer
100 views

Relation Between Flynn's Taxonomy and Concurrency

I have known about the Flynn taxonomy for a while (SIMD, MIMD, etc.), as well as models of concurrency (actor model, petri nets, etc.). However I am wondering now how they overlap and interrelate. If ...
0
votes
1answer
164 views

Wrap REST API with a Lock to Support concurrent requests in a cluster environment

We are dealing with a third party API that doesn't handle concurrency, and we don't have access to the database directly. Our client application is deployed in a cluster environment and has multiple ...
2
votes
1answer
195 views

Designing a pause'able & resume'able task handler

I don't think the title describes the situation exactly. I apologize for the poor description. I'm trying to write a software system, in C++, that will have a heavy job (scanning the file system for ...
2
votes
2answers
280 views

Synchronise work across docker containers in a queue

I have a rather simple (i thought) setup that causes me some grief. I am using a queueing system (AWS SQS) and a few worker docker containers with code written in .net core that pull from a queue and ...
0
votes
2answers
101 views

Struggling with implementing synchronization or concurrency

In my app two components A and B, have their data and state based on the data and state of a 3rd component, component C: Both A and B can change the data of component C. Both A and B listen to ...
0
votes
1answer
175 views

Pessimistic concurrency in a web application

I am working on an application that will support working in multiple tabs at the same time. Currently, when a document is locked by a user, other users won't be able to acces the same document but the ...
1
vote
2answers
88 views

How to model a status log that doesn't allow duplicate statuses sequentially

I need to model the status of an object over time. I'm looking for the best way to model this so that concurrent database connections can look at the current status and update the status if the newer ...
-6
votes
1answer
66 views

two processes with same execute time [closed]

Process A take 10 seconds to finish an execution. Process B take 10 seconds to finish an execution. Is it possible to take 5, 8, 15 seconds to finish an execeution if they run stimulately.
3
votes
2answers
670 views

What is an “active thread” in Java?

From this discussion, there are two opinions of what Thread#activeCount() returns. An "active thread" is actually executing bytecode. It is a thread that was started and is not waiting on IO or on a ...
0
votes
2answers
227 views

Optimistic locking with business constraints [closed]

Consider this simple example: Tables (in a restaurant) can be booked for a period. Business constraint: No two table bookings for the same table may overlap in time. How might one prevent business ...
0
votes
1answer
188 views

Hexagonal Architecture and database concurrency

I have been reading Alistair Cockburn's article on Hexagonal Architecture. One question that occurs to me, is how to handle situations where there are database concurrency issues. An obvious example ...
1
vote
0answers
73 views

What is the benefit of this actor pattern for HTTP handlers in go

I've been reading a few go blogs and and more recently I stubbled upon Peter Bourgon's talk titled "Ways to do things". He shows a few examples of the actor pattern for concurrency in GO. Here is a ...
1
vote
3answers
857 views

Why is a duplicate database Insert fault not considered a Concurrency Error?

A textbook I am teaching from about ASP.Net using ADO.Net in C# says: Note that concurrency checking isn't necessary here, because a concurrency error can't occur for an insert operation. The ...
4
votes
1answer
108 views

Actor Model is it ideal for Controlling Concurrency

so I am thinking of using the actor model to solve a problem I currently have. For brevity, I have made up a scenario so we don't get too technical. Lets say I have 3 benches but each bench supports ...
5
votes
1answer
353 views

Nodejs cluster: are there any downsides?

I was reading a litte about clusters in nodejs, and in all cases it was trivial to clusterize the application. In fact, it was so easy that I began to wonder: are there any cases that I shoudn't use ...
1
vote
0answers
82 views

How Functional Programming addresses concurrent increment/decrement operations invoked by different users? [duplicate]

Using Functional language, How can 2 different parties achieve the result of increment/decrement operations concurrently? For the below scenario, Let's say, I've 2 quantities in stock and 2 users in ...
1
vote
2answers
422 views

How Functional Programming addresses concurrent increment/decrement operations invoked by different users?

Using Functional language, How can 2 different parties achieve the result of increment/decrement operations concurrently? For the below scenario, Let's say, I've 2 quantities in stock and 2 users in ...
-6
votes
1answer
108 views

Concurrent password cracking

I am writing a utility in Go that concurrently attempts to crack passwords given a salted hash and the salt. That part works fine, but now I'd like to take advantage of go routines and have them crack ...
0
votes
2answers
199 views

How handling CPU-bound tasks can be implemented?

I understand task as task in C#, but this questions is not related to C#. Let's say I have single thread and two tasks (both CPU-bound). I would like to run them concurrently, without running one of ...
10
votes
4answers
275 views

What are possible ways to avoid duplicates when you can't add an unique index

I'm stuck in a concurrency problem. Is a typical problem where the user sends 2 o 3 transactions to persists some data that SHOULD NOT BE duplicated in the DB, in case of a duplicate record you ...
3
votes
1answer
838 views

Alternative to Actor model

My main experience working with multithread environment was using Scala, so if I had an object that was concurrently updated by multiple threads I always used Akka. Now working in Java environment I ...
0
votes
2answers
247 views

Updating an object without locking or corruption in Java?

Let's say you have a multiplayer game where different player threads are constantly updating the same game state. How do you best update this state without suffering locking bottlenecks or corrupting ...
0
votes
1answer
155 views

ES / CQRS concurrency

Trying to understand concurrency with CQRS, I came across that question: https://softwareengineering.stackexchange.com/a/349575/286881 But there is something I don't understand when it is said that: ...
0
votes
1answer
39 views

How could I pipeline two sequential workflows where there is room for overlap in the processes?

I'll break this post into two parts, because I'm trying to abstract the concept, but will explain my implementation at the end. I have two workflows, Workflow A and Workflow B. Part of Workflow B ...
-1
votes
2answers
490 views

Straight line coding - How multithreading simplify asynchronous workflow?

Java author mentions: Threads can simplify the development of complex systems by turning complicated asynchronous code into simpler straight-line code. Again the book says: Threads make it easier to ...
1
vote
0answers
133 views

concurrency via message queues: how to avoid recursion?

I am working on a concurrency system based on message queues with an underlying thread pool. A queue can target other queues. Also a queue can be targeted by multiple queues (i.e. children) to create ...
2
votes
1answer
258 views

Automatic blocking/unblocking of allocated seats in a movie ticketing system [closed]

I am trying to build a movie ticketing system. But I am not able to figure out how to solve the below use case: Let’s say there are 10 seats namely S1,S2,S3,S4… S10. Now let’s say that User1 had ...
12
votes
5answers
3k views

how many cores should I utilize for calculations? #cores or #cores -1?

I have a large calculation to do. While I can utilize all cores, I thought is there any reason to leave off 1 core and not to utilize it? (calculation cpu only no IO). Or am i underestimating the OS ...
0
votes
2answers
830 views

Threads - When to use barrier?

Using python syntax, threading.Barrier(NUM_THREADS) establishes a control point and all participating threads block until all of the participating “parties” have reached that point. It lets threads ...