Multi-threading related questions including technique, structure, and safety issues.
-5
votes
0answers
64 views
Running two pieces of code simultaneously? [on hold]
I'm creating a game of my own in Turbo C++ and as it turns out I need to run two functions simultaneously in order for a particular part of my game to run.
i want to run three loops simultaneously.
...
1
vote
1answer
78 views
Transitioning from C++ multithreading to Java multithreading
In C++, I've been accustomed to using threads in the following way:
#include <iostream>
#include <thread>
#include <mutex>
std::mutex m;
int i = 0;
void ...
-1
votes
0answers
30 views
multi-consumer multi-queue rabbitMq Spring (read message by message for each consumer process)
The goal of this project is a bit technical but hopefully to have someone to advise me better.
Note that I work in a multi-clustering context, which means that I have the same program running on ...
1
vote
0answers
19 views
ODBC 3 Multiple Statements vs Multiple Connections
So right now I have a single thread to handle all the requests for the database. Let's say I have 400 requests per second for logins / logouts / other stuff, and 400 requests per second which are only ...
4
votes
3answers
223 views
Queue vs Threads
I'm implementing a data processing software. The software gets form the network thousands of events that must be processed in according to rules. I implemented a multi-thread service, which receives ...
0
votes
0answers
43 views
Merging waitable objects
Lets say you have two (or more) objects from which both allow a thread to wait for an event to occur.
Foo.Wait(timeout);
Bar.Wait(timeout);
The main thread wants to wake up when either of these ...
0
votes
1answer
67 views
Blocking queue for token based synchronization
I'm currently looking for a good solution for the following use-case in C++ (preferably C++11 or C++14):
The program is running a server with a TCP connection. Other clients can connect at any time ...
4
votes
4answers
505 views
Generate a random color for every user and keep track of created colors. Every color MUST be different
In my app every user that connects to the server needs to get a random distinct color and I have to keep track of them. About 20 to 30 will be connected in the same time. When a user disconnects, his ...
1
vote
4answers
306 views
What is the ninja performance gap, why is it so large, and how can we overcome it?
According to this abstract:
The "Ninja gap" [...] is the
performance gap between naively written C/C++ code that is parallelism
unaware (often serial) and best-optimized code on modern
...
2
votes
1answer
125 views
How to implement a (truly) global variable in a Rails app
How can I best implement a global counter in a Rails API app? (A central component in a system with several.)
Basically I have a transaction id I need to increment and roll over past a maximum value. ...
0
votes
1answer
127 views
How to let multiple threads write on the same file [closed]
I have got a text file called "vholders.txt".
I am making multiple threads as you can see here ,those threads work with their own given data and at last they write their own output to the ...
0
votes
0answers
96 views
Java Multi-threading
I was solving this question in Java where the user enters a partitioned array. The computer then determines what all elements from that array can be used as pivots. (Pivots are the same pivots that ...
0
votes
1answer
33 views
ThreadPool.QueueUserWorkItem is this example a valid use case?
I need to send out a batch of reminder emails, never more than 100 emails per batch, using authenticated SMTP. This is happening on a WindowsService (no GUI).
The SMTP library we're using raises a ...
2
votes
1answer
101 views
Does it make sense to have a user specified thread limit?
I'm developing a C++14 application and would like to take advantage of the new multithreading features, in particular std::async. I have seen a number of applications which allow the user to specify ...
0
votes
1answer
65 views
Create/destroy multiple threads for animations/light effects
I'm developing a program for the Razer Deathadder and Firefly, I am going to create new light effects for the Firefly. I'm doing this in C# with the Colore library.
Now these light effects will be ...
0
votes
0answers
58 views
How to prevent parallel calls to model?
While there is some command running which calls methods on some model, how to prevent concurrent calls for critical places in that model?
If multiple requests comes in then they should maintain their ...
3
votes
3answers
137 views
What is “Split Data Model”, mentioned in the book “Java Concurrency In Practice”?
I'm learning Java multithreading programming by the book "Java Concurrency In Practice". In chapter 9.4.2 Split Data Model, I read this:
From the perspective of the GUI, the Swing table model ...
1
vote
1answer
38 views
Coordinating threads in a multithreaded server
The goal is to develop something similar with a quiz application: there is a server to which players connect. At some point, a game is started. The game consists in asking the players a few multiple ...
3
votes
6answers
185 views
OpenGL, multithreading, and throwing destructors
How do you make an class that properly warns a developer in the future that they've made a mistake somewhere in their implementation that resulted in an object that gets deconstructed in a state that ...
0
votes
2answers
46 views
Double-check locking around initialisation which performs a web request
I've just refactored some code that managed a global state cache of values that didn't have locking to use double check locking. Other than moving the initialisation to a single source (the cache was ...
6
votes
2answers
168 views
Advice for designing API request rate limiter?
I'm in the planning stages of a web application that makes heavy use of data retrieved from a third party's REST API. This data is cached on the server and requested by clients via AJAX. The REST API ...
6
votes
1answer
91 views
Python: Control subprocess from calling thread
I am working on a database interface to a MongoDB using Python Eve as an API.
The database stores several documents containing parameters and values needed for some calculations. I wrote a Python ...
2
votes
2answers
145 views
Java Thread.sleep() considerations
I've been doing some testing in an app that I've been involved with for the past little while, and it appears as though some of the code we've written is causing a race condition.
What's happening is ...
1
vote
2answers
116 views
Thread-safe events — locking on privately held references
I was reading about delegates and events on this webpage to get a better understanding of them and how they relate to each other. While reading, I came across this statement:
That goes against ...
4
votes
2answers
288 views
What is it called when threads are waiting but not deadlocked
The definition of a deadlock is when two or more threads cannot complete their execution because they are mutually blocked and waiting for something from the other thread(s).
Is there a similar term ...
1
vote
4answers
275 views
Why is dealing with multiple threads considered difficult? [duplicate]
You can say this is opinion based, but the problem is that everyone's opinion on this issue is same.
Even the lead developers say that creating the threads is easy, dealing with them together is ...
10
votes
2answers
417 views
Why do programmers define programming models to replace C/POSIX for parallelism?
Providers of new computer architectures regularly try
to introduce new programming models, e.g. recently
CUDA/OpenCL for GPGPUs, and displace C/POSIX as the
control interface to platform ...
3
votes
1answer
118 views
Minimizing lock time (multithreaded app)
I have a web application written in C# which uses external dll written in C++. Communication between clients (web browsers) and a web application is done using SignalR. For communication between web ...
1
vote
0answers
55 views
When do you need precision with thread execution timing and how do you do it with Java? [closed]
(Under software architecture/design)
I'm not sure how my question could be subjective but the message next to the title suggests that it is.
I hope I'm not violating the rules here.
Under what ...
1
vote
0answers
30 views
Push instead of pull on a list that might change due to a command in addition to events? [closed]
I need to show a refreshable/searchable list of items and update/add-to it whenever an event is published. How do I make sure no events are lost while refreshing/searching is happening?
Some sort of ...
1
vote
0answers
89 views
Running simulations in parallel, managing each separately [closed]
Let me preface this by admitting that I am a novice - this is the first real project I am doing outside of a class.
I am running a single-threaded C++ simulation several hundred times (i.e. I have ...
-1
votes
1answer
68 views
Approaches to Concurrency [closed]
I’ve been doing some research on the various approaches to concurrency, and I’ve ended up with the following taxonomy:
Manual thread based concurrency with locks
Asynchronous dispatch queues and ...
5
votes
1answer
88 views
Pthread scheduling (System and Process)
I've read the operating system concepts 8th edition written by abraham silberschatz. However, I don't understand Pthread Scheduling.
Thread-library schedules user-level-threads on LWP(Lightweight ...
4
votes
1answer
91 views
Threads: the difference of concurrency between many-to-one model and one-to-one model
I am studying "Threads" part with a textbook, Operating system concepts written by Abraham Silberschatz, Peter, Greg.
First, I'm going to say something in the textbook related to my question, and ...
2
votes
4answers
166 views
Is it a good idea to make method behavior depend on the calling thread?
I want to subclass a 3rd party class, in order to make it thread-safe.
I have a good idea of how to implement this, but there is a problem: the superclass has a property, which affects the behaviour ...
1
vote
2answers
125 views
Don't quite understand check and set in concurrency
I don't entirely understand check and set behaviour.. here is an example:
public static void main(String[] args) {
List<String> list = Collections.synchronizedList(new ...
1
vote
0answers
79 views
Better choice of Queue then a ConcurrentLinkedQueue if I have low number of threads in Java
I have two threads, one that is reading messages from the web and putting them into some sort of a queue. The other is suppose to read it. I looked into a ConcurrentLinkedQueue and it looks good for ...
5
votes
1answer
127 views
How can I best test a multithreaded C producer-consumer program? [closed]
How does one best write tests for a multi-threaded producer-consumer C program?
I know GDB can be used to debug threads, but I believe GDB also stops the thread currently being debugged while other ...
1
vote
0answers
80 views
Terminology - Difference between thread and process and how they manage DB connections
I've been working more with concurrency in Ruby recently, and I keep seeing various articles using "threads" and "process" interchangeably.
What are the actual definitions of these terms? Is a ...
1
vote
0answers
40 views
Cost of cache coherency/sharing data across multiple cores?
If I have two CPU cores, one is writing a particular cache line and the other core wishes to
Read
Write
the same cache line, what are the costs (in cycles) for doing so?
I am a little unsure ...
3
votes
1answer
89 views
Eliminating thread affinity requirements when converting an STA COM object into an MTA COM object
Suppose I need to convert an STA COM object into an MTA object. Single threaded apartments guarantee not just that only one thread will call the object at a time, but that it's always the same thread ...
2
votes
1answer
1k views
Thread.State BLOCKED vs WAITING
What is difference between the BLOCKED and the WAITING states of a thread.
As per JAVA code comments
/**
* Thread state for a thread blocked waiting for a monitor lock.
* A thread in ...
0
votes
2answers
172 views
What happens to lock's state and methods when a thread acquires a lock?
Assume I have following class
class Student{
void method1(){
// Do Something
}
void method2(){
// Do Something
}
}
And the object of this class is used as monitor in ...
35
votes
4answers
4k views
Why is it the caller's responsibility to ensure thread safety in GUI programming?
I have seen, in many places, that it is canonical wisdom1 that it is the responsibility of the caller to ensure you are on the UI thread when updating UI components (specifically, in Java Swing, that ...
9
votes
1answer
124 views
Do classes in a JRE library support observable and/or asynchronous reads from external/non-JRE assemblies?
How can I implement my cross-platform library (e.g. on JRE) to operate in a thread-safe manner on object references, so that native front-ends on other platforms can observe the object and take ...
0
votes
1answer
113 views
Thread synchronization for multiple threads accessing a message stream
My project has a single message stream (communicating with an external device) which is accessed via multiple client threads. The workflow is:
There is a thread (the "messaging thread") which reads ...
4
votes
1answer
336 views
C# async/await: Pedantry vs. the Debugger
I'm playing around with async and await, and they seem pretty intuitive, but some of the things I'm reading about these keywords doesn't make sense to me. In fact, some of it seems to me to be ...
2
votes
1answer
149 views
Multithreading with triple buffer, do I have to do the waiting for the condition variable?
I have a triple buffer implementation that is often used in threads in such a way that when new data is expected, there's always a WaitData(n) function called on the buffer (A condition variable's ...
0
votes
1answer
287 views
Performance of sharing single object with multiple threads in Java
In Java, if I create an object that has a method to do something, and I pass that object to multiple threads which call the method, is there a performance difference from creating an individual ...
4
votes
2answers
72 views
Preemptive scheduling with “do not disturb”
In this answer about threading it is said:
In preemptive scheduling, a thread can be interrupted at any time, either by a timer interrupt or any other interrupt or during a system call. The part ...