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

learn more… | top users | synonyms (5)

4
votes
1answer
38 views

Should I implement the consumer/producer pattern in my java video app, and if yes, how?

I built a small video frame analysis app with desktop Java 8. On each frame, I extract data (5 doubles now, but could expand to a 1920x1080x3 OpenCV Mat in the future). I would like to store this data ...
0
votes
0answers
30 views

Java write to text file from multiple threads

I have a thread which read and insert new lines in same file. I must synchronized that file so that no other thread is not accessing the file at the same time. Here is how i will synchronize a file ...
4
votes
2answers
289 views

Const means Thread-safe?

I was put onto this video: http://channel9.msdn.com/posts/C-and-Beyond-2012-Herb-Sutter-You-dont-know-blank-and-blank By http://codereview.stackexchange.com/users/39810/glampert Because I asked ...
1
vote
2answers
66 views

Concurrent collections, should read methods allow multiple threads at one time?

I have custom collection and I want to add wrapper to allow concurrent access. public class MyConcurrentCollection<T> { private MyCollection _collection; // passed in constructor ...
0
votes
1answer
47 views

Multithreading message broker in a transactional system - Best Practice [closed]

We have 2 systems that exchange tickets base on a transactional flow, they have an order in the ticket statuses if one status does not reach one system all the flow is stuck. The problem is that we ...
0
votes
0answers
20 views

How to run a function after returning 201 view [migrated]

I'm using the Django Python framework with the Django REST Framework. When a new instance of a model is saved, I need to generate a PDF that is saved locally on the server. Is there a way that I can ...
2
votes
1answer
101 views

How much physical memory is consumed by the stack of a .NET thread?

In Stephen Cleary's article in MSDN magazine "Introduction to Async/Await on ASP.NET" he says that "every thread pool thread on a modern OS has a 1MB stack." (modern OS == Windows 7/8 for this ...
3
votes
1answer
85 views

How is atomicity of reference operations enforced?

In managed languages how is atomicity of reference operations enforced? On some platforms references have to be at least 64 bit, so it cannot rely on usually atomic 32 bit word operations... Is it ...
-1
votes
0answers
21 views

Best way to get data from database inside Thread Class in Spring [migrated]

Currently i am troubling that how to get data from database inside my thread class. I can't make bean of my thread class because new instance is created of thread on every request. MyThread.class ...
3
votes
2answers
108 views

are multithreading, multiprocessing, multitasking implemented at instruction set or OS?

On a computer with a single cpu core, must a multithreading program be implemented based on an OS? Can it be implemented in the instruction set and run without an OS? Can multiple programs run in ...
0
votes
1answer
100 views

How shall I handle event loop exceptions?

What is the best practice for handling exceptions thrown from event handlers/listeners in a event loop? For example: class EventLoop { public: void start(); //create a thread which calls run(); ...
2
votes
1answer
59 views

Should a lockfree queue use a condition variable?

Suppose I have a lockfree queue in a multithreaded setting. I already provide a try_dequeue() method which allows for an optional failure (communicated via the return type) if the queue is empty. ...
1
vote
2answers
112 views

Why don't we see (more) widespread adoption of lock-free dynamic memory allocators? [closed]

In a multithreaded programming environment, lock contention on the heap is often enough a performance bottleneck. Theoretically at least, the cream-of-the-crop solution for this problem is to have ...
1
vote
0answers
75 views

Concurrent directory-tree search

I am trying to get familiar with concurrent programming, and have picked up an excercise to use a fixed number of threads that search through a directory structure. This is pretty much the way it is ...
4
votes
2answers
115 views

Why don't all UI Control methods RunOnUIThread

In both .NET and in Android and I'm sure other frameworks I've noticed this issue where you end up with a task that takes too long and so holds up the UI thread. Say you have a method that updates a ...
0
votes
1answer
84 views

Controlling concurrency by Thread Pool in scenario of CPU-intensive and I/O intensive requests?

My goal is to understand how to handle jobs coming from the client side at very high frequency each job is either CPU-intensive or I/O intensive, but both types of jobs are continuously arriving at my ...
53
votes
12answers
8k views

Why would a program require a specific minimum number of CPU cores?

Is it possible to write code (or complete software, rather than a piece of code) that won't work properly when run on a CPU that has less than N number of cores? Without checking it explicitly and ...
1
vote
3answers
182 views

Is there an algorithm to determine the amount of work needed to keep workers busy?

I wrote a multi-threaded program that randomly generates strings, and after generating, checks to see if the string contains a certain value. Namely, StringGenerator and StringChecker. What I'm trying ...
6
votes
3answers
300 views

Design solution for communicating between multiple layers

We are developing a framework that has several layers and would be deployed in a multi-threaded environment. Each layer may have its own input/output data type. The top layer takes the input, performs ...
2
votes
1answer
169 views

Most efficient/cleanest way to Kill a recursive thread safely

I have a number of worker threads which all perform a flood-fill task on different regions of a bitmap. They all make calls to a recursive sub-routine with different parameters(coordinates). Fyi, I am ...
1
vote
2answers
259 views

How to Keep Track of Thread Safe Code in a mostly Thread Unsafe Legacy Rich C++ Code Base

For large legacy C++ code bases, notions like Herb Sutter's "const means threadsafe" don't seem to help much, because there can be an overwhelming amount of code in const functions which are modifying ...
7
votes
1answer
184 views

Message Queue for RTOS for microcontrollers

I'm currently writing an RTOS for microcontrollers. The whole thing is written in C++11 - if anyone is interested, and the link to the repository is at the bottom. Currently I'm writing a class that ...
4
votes
1answer
227 views

What is the advantage of 'SwingUtilities.invokeLater()' method?

For the below sample GUI program using javax.swing, public class UnResponsiveUI extends JFrame{ private boolean stop = false; private JTextField tfCount; private int count = 1; /* ...
2
votes
1answer
73 views

Can concurrent code (threads, distributed computing, etc.) be directly ported to single-threaded/non-networked platforms?

Take an arbitrary "perfect" multi-threaded program, on an arbitrary multi-threaded platform, using an arbitrary programming language. Assuming that this "perfect" multi-threaded program: is ...
-2
votes
2answers
108 views

Using a global struct with pthreads in C [closed]

I'm trying to simulate clients going into a bank and being served by tellers over a period of time. I am using a thread to determine if a client came into the bank via an arrival rate and am using ...
7
votes
4answers
559 views

How to prevent others from using non-thread safe variables in a multithreading environment?

I have an application written in C++ that was originally single threaded, but, due to the increasing complexity of this project, I'll need to expand it to at least two or three threads. There are ...
0
votes
5answers
250 views

Race conditions in JVM languages versus C/C++

I was thinking about thread synchronization issues in compiled languages like C++, versus synchronization issues in languages like Java. I'm wondering how a JVM language like Java doesn't (at least ...
0
votes
3answers
195 views

Socket Connecting to Large number of IPs

I have a text file of ~600 CIDR notation IP blocks which, when expanded, amount to ~17.5M IP addresses. I need to socket connect to each one. If it connects, I add it to a "live" list, if it returns ...
2
votes
0answers
45 views

Evaluating concurrent application design approaches on Linux

Working on relatively low-speed hardware, I need to grab a snapshot of a rapidly changing datastream and then post-process the snapshot data and save it to disk. I need help with designing the ...
6
votes
2answers
645 views

Does laziness yield more race conditions?

I recently ran into a race condition while accessing a configuration setting. After examining what I could of the code, I came to the conclusion that the Configuration class' laziness1 was the source ...
1
vote
2answers
217 views

How does the consumer-producer solution work?

I'm only a beginner, and my book doesn't cover this subject. I have researched my problem and found that an implementation of the consumer-producer pattern is the ideal solution, and have Googled it, ...
3
votes
1answer
118 views

Seeking Guidance on Thread Safe Scripting

I am trying to write a script that will take multiple paths to files on various servers, search them all simultaneously, and return a single list of results to a user. Initially, I was just using ...
0
votes
2answers
278 views

Java Multithreading and CPU cores [closed]

I have a simple question this time. If I write an java application with 4 Threads ( each thread does different work ), what will be the difference between single-core, dual core and quad core cpu ( ...
4
votes
2answers
294 views

Is it better to create thread safe subclasses or make the main class thread safe?

Say we have a class that is frequently used in a single-thread context: public class Foo { public List<Bar> Data; public virtual void ChangeData() { for(var i =0; i < ...
0
votes
1answer
240 views

I/O bound or CPU-bound

I have a telephony application, there is a windows service(third party product) running on a remote server. The application runs against the server. To connect the server, we have the code. public ...
4
votes
2answers
676 views

Would this be a proper use of threading?

After reading various MSDN articles, tutorials, and posts on here I came up with a design for a windows service that I wanted to make sure my threading strategy is proper and won't lead to memory, ...
35
votes
10answers
10k views

Why should your code not use 100% CPU? [closed]

I'm speaking specifically about a C# .NET 4 program running on Windows XP or higher, but general answers are also acceptable. Assume an already optimized and efficient program. The problem here is ...
1
vote
3answers
247 views

Context Switching behavior?

I need to ask a question that have been bugging me for some time now: If I have a single core and one OS thread, this thread will get 100% of the CPU time and all is good. If I have a single core ...
1
vote
1answer
62 views

How to effectively split jobs into groups for multiprocessing when the job sizes are unknown

With K processor cores, how to optimally split N jobs into groups, with each group to be processed sequentially by one processor core, when the time to process each job is unknown ahead of time and ...
0
votes
1answer
180 views

Android, using a Fragment to hold/edit complex object, accesible from any Activity

I'll do my best to describe the problem, but I'm still very new to several concepts that I think this problem requires to be solved (namely interfaces and threads). I should preface this by saying ...
0
votes
2answers
198 views

When is lock not needed in multithreading

I want 500 objects to be processed concurrently using multithreading. These objects will have some initial data before the threads are created. I am creating 5 threads and each thread takes 100 ...
1
vote
1answer
236 views

Pass Event between Systems in a multi-threaded Entity-Component-System

Is there a way to pass Events between Systems in a multi-threaded Entity-Component-System that realizes the benefits of saving on system resources? I've read a german article about the ...
0
votes
0answers
79 views

Using Singletons in JS with workers

I'm building a javascript application that does continuous drawing, but relies on asynchronous scripts in the background which also need to poll for events and write to "global variables". This got me ...
2
votes
4answers
528 views

Why aren't we building and using parallel processors *meant* for general computation?

We all know GPUs are much faster than CPUs for a wide range of applications. When someone asks why we are not just programming for GPUs at all, one of the most common answers is that GPUs are not good ...
3
votes
2answers
194 views

Are there alternatives to using an optional type in a multithreaded environment?

I'm making an MPMC queue in C++, and I would like to find out what the best interface for a try_dequeue method would be (I'm not concerned about its implementation). I'd like to provide a method which ...
0
votes
3answers
183 views

How should be the approach to start thinking about multi thread programming [closed]

I am an experienced java developer.Of now I have started learning multithreading in java.I am able to grasp most of the concepts but still I am unable to visualize applications running on threads.I ...
0
votes
3answers
299 views

BackgroundWorker starting again in Completed event

I want a background worker to continue running and occasionally update the user interface. My first idea was to use a BackgroundWorker and in its completed event just fire it up again. Is using a ...
1
vote
1answer
141 views

Multithreaded Pre/Post Functions

I'm programming an application for an embedded device. We are using an RTOS that supports multi threading. The device is supposed to mimic an older project that was programmed in plain C (without ...
4
votes
1answer
192 views

Error Handling Strategies in Multithreaded Environments

TL;DR What error generating and handling strategies do you use in Multithreaded code intended for use by others and why do you use them? If applicable, state what programming paradigm it's useful for. ...
1
vote
1answer
142 views

Synchronized access to network industrial equipment

I have an industrial equipment which is controlled by a software. The software connects to it using sockets, and keeps the connection all the time alive, while from time to time sending commands to ...