Stack Exchange Network

Stack Exchange network consists of 174 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.

10
votes
5answers
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 ...
0
votes
0answers
57 views
+200

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
103 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
1answer
111 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 ...
-3
votes
1answer
92 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 ...
0
votes
1answer
121 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
92 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
73 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
0answers
26 views

How to architect priority ordered processing between two apps with multiple threads producing/consuming requests?

Apologies if the title of the question is bit misleading. I have two apps X and Y both implemented in java. App X runs in apache servicemix container and Y is web-app running in jee app server (often ...
0
votes
1answer
48 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
149 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
90 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
80 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
86 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
87 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 ...
-5
votes
1answer
61 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.
2
votes
2answers
293 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
169 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
106 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
46 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
583 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
102 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
190 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
73 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 ...
0
votes
2answers
335 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 ...
-5
votes
1answer
88 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
172 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
269 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 ...
4
votes
1answer
435 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
147 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
124 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
418 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
98 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
161 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
2k 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
0answers
117 views

Designing high concurrency sale

I am facing issue trying to design it correctly. Problem is simple- there is 1-click button to buy one type of coupon. It is single row entry in DB with 1000 as stock count. Assume QPS as 1 million ...
0
votes
2answers
612 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 ...
5
votes
1answer
99 views

what is the best practice for synchronizing requests trying to update the same resource in RESTful APIs?

This question is not about a specific framework. but I'm currently working with asp.net core. The problem I'm facing is the concurrent update of a resource in the web application (race condition). I'...
15
votes
4answers
4k views

Why coroutines are back? [closed]

Most of the groundwork for coroutines occurred in the 60s/70s and then stopped in favor of alternatives(e.g., threads) Is there any substance to the renewed interest in coroutines that has been ...
14
votes
2answers
2k views

ES / CQRS concurrency handling

I recently started to dive into CQRS / ES because I might need to apply it at work. It seems very promising in our case, as it would solve a lot of problems. I sketched my rough understanding on how ...
0
votes
1answer
549 views

Design pattern for streaming data?

I have a use case where I'm asked to read an XML document that is a list of data, break it up into data sub-elements, and transform those sub-elements (in order) into another document format (like a ...
3
votes
0answers
116 views

Some “intent”-related questions vis-à-vis Operational Transformation and CRDTs

I’m a little unclear on some questions relating to the "intent" part of concurrent collaboration algorithms (operational transformation and conflict-free replicated data types). Please help! Strings ...
2
votes
0answers
52 views

Handling frequent simultaneous updates in real time

I have seen similar questions and answers here but my situation is a bit different from those. I am building an application which gives users infinite canvas space to draw something. The canvas space ...
-1
votes
1answer
263 views

languages with native thread support

I am investigating ways of making my bundle of python network-requesting processes more efficient and became interested in the likes of Go and Julia for their apparent strong concurrency support and ...
-3
votes
1answer
201 views

Producing Consumers Thread Pool

I’m coding a Hash-Life implementation in C++14 and working on a multi-threaded implementation. It has obvious potential for multi-threading. The task can be broken down into essentially 13 sub-tasks. ...
2
votes
1answer
12k views

Correct usage of async/await and Task.Run()

I am developing an application that will read excel files from disk and then process tests based on the data in the files. In order to keep the user interface from locking up when loading files and ...
-1
votes
1answer
378 views

When is it More Appropriate to Use Java Thread instead of Quasar Fiber?

I've browsed around about Quasar fiber yesterday and it seems that it's more lightweight than Java thread based on the following demo. My questions would be: Are there any scenarios that thread is ...
1
vote
0answers
80 views

Concurrently parsing records in a binary file in Go

I have a binary file that I want to parse. The file is broken up into records that are 1024 bytes each. The high level steps needed are: Read 1024 bytes at a time from the file. Parse each 1024-byte "...
1
vote
1answer
339 views

Small Mutex Implementation?

The relatively large size of std::mutex on different platforms (e.g. 40 or even 80 bytes) is often explained as ensuring the mutexes don't occupy the same cache-lines and so don't incur logically ...