Multi-threading related questions including technique, structure, and safety issues.

learn more… | top users | synonyms (5)

0
votes
1answer
38 views

Possiblity to request several Linux threads scheduled together (in the same time)

I'd like to be able to request Linux to schedule two or more threads in the same time. I mean today when my multi-threaded program is being executed I know that in worst case only one of my threads is ...
1
vote
1answer
70 views

How to test software with near-real-time requirements?

So, I've been refactoring my videoconferencing application for a while, covering it with unit and general tests. Finally, I got to the point where I need to write a loopback test with 1 client sending ...
0
votes
1answer
96 views

How to avoid nested Threads?

I often have a situation where I first need to do something in the UI thread (Android in this case), then to some networkstuff in an extra thread, switch back to the UI thread and udate the layout, ...
0
votes
2answers
107 views

How to make two threads interact with each other without stopping the execution of the thread?

This might sound similar to some of the other questions but it does not deal with wait or notify. I have two threads which do two different things The first forms a process in the background and ...
6
votes
3answers
558 views

How to properly deal with starvation

I'm trying to find a way to avoid starvation in my program, a producer/consumer (two threads, one for each role) problem with four priority levels (four deques). Basically, the consumer thread always ...
0
votes
1answer
71 views

Is it correct to say that threads enable programmers to expose process internals to the OS scheduler?

Is it correct to say that threads were invented to enable programmers to expose process internals to the OS scheduler?
1
vote
1answer
40 views

Multi threaded and event driven

I got this problem in an interview and want to confirm multi threading adds no value here. Case: You are writing an agent to buy stocks. The agent is initialized with a set of stocks to buy when ...
0
votes
0answers
19 views

QSqlDatabase member inside QRunnable - yes or no

I am working on Async multithreaded Tcp Server in Qt and I am wondering, which approach is beeter: To encapsulate QSqlDatabase as member inside QRunnable To create local QSqlDatabase variable inside ...
0
votes
1answer
51 views

What are the pros and cons of using these Multithreading Models in a Client/Server Architecture

In my classes of parallel programming the teacher mentioned three models, dynamic thread creation (create threads according to demand), thread pool (create a fixed amount of threads) and mixed or ...
0
votes
1answer
126 views

Using database connection on multiple threads

let's say I have a database connection in the class Database which offers the following public methods public synchronized void open() {} public synchronized void close() {} public synchronized void ...
-1
votes
1answer
143 views

How to signal a loop to continue the execution instead of using sleep

I am trying to create a thread that will sit and wait to detect new objects in a vector (the queue). Using a loop will crush the resources on the given machine, so I am trying to figure out how I can ...
2
votes
1answer
87 views

Collect and prcess data from multiple threads in Java

There is a Java program that reads a list of orders and for each order starts a thread that receives data from SQL and prints the list of items in a given order to an order_name.html. I want to write ...
6
votes
2answers
151 views

Do compilers utilize multithreading for faster compile times?

If I remember my compilers course correctly, the typical compiler has the following simplified outline: A lexical analyzer scans (or calls some scanning function) the source code character-by-...
4
votes
1answer
179 views

Potential legal issues with lock-free / wait-free structures / algorithms

While researching the subject matter - lock-free and wait-free data structures - I'm seeing a worrying amount of mention of patents with this area. I've hobby-researched compression algorithms years ...
0
votes
2answers
84 views

Why a thread uses a stack in a context switch?

Correct me if I'm wrong, but if I have an operating system that makes a context switch, then that context switch is in practice a switch from one thread to another, where one thread was running one ...
4
votes
1answer
110 views

Monitor.Enter() when a thread is of highest priority

Background Okay, so let's say I have some high priority (ThreadPriority.Highest) thread t which needs to enter a critical region in order to consume some data. I will use the following code snippet ...
1
vote
2answers
204 views

multi-threading performance when CPU is maxed out

I've noticed my software severely degrades when the # of threads is substantially increased. What I mean is that when I limit the # of threads, the performance is much better than when I just let ...
4
votes
2answers
104 views

How to facilitate thread-safe access to large set of shared variables?

I have 2 sets--inputs and outputs--of 70 32-bit integer variables and 70 bools (140 vars altogether). These need to be accessed and modified from 3 threads. What is an appropriate design pattern to ...
3
votes
1answer
81 views

Is there use case for implementing a callback if a future is returned?

If I have function which returns a future, is there any reason to also include a callback where the callback is simply called right before the future completes? The only advantage I can think of ...
2
votes
6answers
250 views

How does immutability remove the need for locks when two threads are trying to update the shared state?

Okay so I read through this: Does immutability entirely eliminate the need for locks in multi-processor programming? And this was the main takeaway for me: Now, what does it get you? ...
1
vote
3answers
349 views

Do I have to fork a server program as an “C” child process in order for correct interprocess communication to take place?

I would like to implement interprocess communication between an Ubuntu Linux 15.10 mono 4.1.2 C# recorder client and Ubuntu Linux 15.10 mono 4.1.2 C# video server using a C++ mutex class and C++ ...
2
votes
1answer
61 views

How to design a dynamic thread allocator

Forgive the title if it isn't correct, I am just not sure what I am trying to design is called. Say I have a number of tasks I want to run, N. Additionally, I have a maximum number of threads I can ...
45
votes
8answers
7k views

What are the drawbacks of making a multi-threaded JavaScript runtime implementation? [closed]

I've been working on a multi-threaded JavaScript runtime implementation for the past week. I have a proof of concept made in C++ using JavaScriptCore and boost. The architecture is simple: when the ...
0
votes
0answers
85 views

What to use in case of waiting for something that is complete: delegates, events and/or thread

I try to give a concrete example. Create a semaphore for a crossroads. I have two semaphores. I have possibility to set a duration of semaphore 2 minutes, 5 minutes, 10m inutes etc. When one ...
6
votes
2answers
379 views

Why is threading platform-dependent?

I am reading book "Foundations of Qt Development", Chapter 12, and I read that threading is platform-dependent, can someone explain, why? I know how to use threads but that what they said is not so ...
-3
votes
1answer
217 views

C# Share Datatable in Multi-threading

I am beginner in Multi-threading in C# & confuse in current task. My task is to read datatable and display datatable in C# console application using multi threading. I have three threads and one ...
-1
votes
2answers
89 views

Which is better either creating two objects for two threads or one object for two threads?

In the below program, I'm calling method1() of SampleClass from two threads. So, basically I have created two objects for each thread and called the method1(). I have also seen the scenario of ...
-1
votes
2answers
140 views

Lock threads or not lock threads?

I have an application (full-stack) that is used millions of times concurrently. Some vital application properties are managed on the client side (at the time it seemed to be the simplest approach to ...
1
vote
1answer
66 views

«Heavy» object initialization: within each thread or outside and then pass it to the threads as parameter?

Let say there is an array of strings, I have to process. I'm using a «heavy» third-part object which gets the string and performs its analysis. In order to optimize a performance, I create a number of ...
4
votes
3answers
173 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 makeACallFromPhoneBooth()...
2
votes
0answers
69 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
351 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
49 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
77 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
738 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
339 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 multi-...
3
votes
1answer
192 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
401 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 vholders....
0
votes
0answers
120 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
84 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
2answers
228 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
83 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
61 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
204 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
41 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
249 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
51 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
294 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
121 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
286 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 ...