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

learn more… | top users | synonyms (5)

1
vote
1answer
74 views

How to concurrently write data in Java without locking?

How to implement a multi-threaded program in which each thread needs to write/output some data (in any order of course) but without the locking overhead that is involved with files or a particular ...
0
votes
3answers
58 views

Thread priorites - how to? [closed]

Is there some method or logic for defining correct thread priorities in a multi-threaded system which has a pipeline from input to output. For example assume the following pipeline exists: (1) ...
3
votes
1answer
124 views

Implementation of Asynchronous function call in C

I took it upon myself recently to work towards making a general-purpose Translator to automatically translate js programs into C, but I got stuck when thinking of asynchronous behaviour. Using ANSI / ...
0
votes
1answer
86 views

C#/.NET multithreaded application design

The application to be designed serves as a bridge between two different systems. One natively speaks TCP (RS232 actually, but there's a COM->ETH server in the line of communication) - the other one is ...
1
vote
3answers
46 views

Clarification on Acquire/Release Semantics in multithreaded programming

In an attempt to fundamentally understand any concept, I try to understand the meaning of the words within the context it is being used. Currently, I am trying to fundamentally understand the whole ...
1
vote
2answers
52 views

Verifying absence of an event in multithreaded unit test

I've got a legacy application that had a fragile unit test (which is really more of an integration test) that used a lot of Thread.Sleep calls to wait for events to happen. While trying to introduce ...
1
vote
1answer
50 views

Does grouping threads by task improve performance?

This is kind of a lazy question on my part, since I gave up after trying only a few google terms. But when I read about multi-threaded performance, I read about context switching being bad for ...
-1
votes
1answer
58 views

Experimentally determined timing of function/method calls vs locks, signals. Anti-pattern name?

Here is some pseudocode and paraphrased comments: // Allow time for screen to start before content reset. // Delay time determined by testing with platform version 5. delayCall(0.01, contentReset()) ...
0
votes
0answers
14 views

Threads to print numbers sequencially : with even and odd threads running parallely [migrated]

I am new to multithread programming. I tried to print numbers sequentially using even and odd number printing threads, running in parallel. When executed, the code enters a deadlock. Can anyone help ...
4
votes
3answers
1k views

Best way to define, start and stop threads in C#

I am making a little program, which have few Threads, constantly running. At some point, I may want to stop one of them, and then, after random period of time, to start it again. So first, what is the ...
1
vote
1answer
30 views

asp.net tracing custom implementation

I want to do event tracing in asp.net. That is whenever any method is called, i want to log some method specific details into a text file like method name, return value e.t.c But, as requests will ...
-1
votes
1answer
35 views

What's the best way to implement a real time show board to show results from concurrent result producers in Java?

I'm making a load test tool that launches multiple thread to simulate load on the target server. Each thread executes a predefined set of commands in the structure of TestSuite - TestCase- TestStep ...
0
votes
2answers
53 views

Why should we expect user-space coroutines to be lighter than OS threads?

I have heard it said that managing concurrent TCP connections using user-space coroutines uses less resources per open connection than using an OS thread per connection. Actually, OS threads and ...
1
vote
0answers
70 views

Android: How to set a stop flag in native C thread from Java

In my NDK Android app, Java part runs native C code to perform intensive calculations. It does so by creating an AsyncTask worker object that runs the native code in a separate thread via the JNI. The ...
3
votes
3answers
127 views

How many threads should I use in my NIO server?

I've built a Java NIO TCP server, it currently uses four threads. One ServerRunnable thread that uses a selector and three worker threads. I've been looking around for some information about this, ...
2
votes
1answer
96 views

Strategies for handling or avoiding race conditions

I'm working on a .NET application where I off-load my DB work (save operations) to a separate thread (inspired by how NodeJS handles IO operations). A save operation comes down to this (using Entity ...
1
vote
1answer
55 views

What are the underlying patterns in systems allowing asynchronous operations?

Say I'm working with a system that allows async, nonblocking operations. If I queue up a set of those operations and specify their result buffer references: nonblocking_write( message, write_buffer ...
0
votes
0answers
112 views

How is CancellationToken.IsCancellationRequested updated?

I've been doing some refactoring today and I encountered one interesting thing. I've extracted a method from a code which uses a cancellation token passed to it in order to check if the user did not ...
3
votes
2answers
142 views

Design, how to utilize The Hardware (multiple threads and/or GPU) while indexing (via a database) a very large set of binary files

Problem How can design my file parser to maximize the hardware when processing (creating meta data for) a large file (i.e. how to avoid being blocked by IO and running out of memory) preferably ...
4
votes
1answer
114 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 ...
1
vote
0answers
134 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
377 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 ...
2
votes
3answers
195 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
59 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 ...
2
votes
1answer
141 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 ...
3
votes
2answers
148 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
118 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
86 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
140 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
79 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
163 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
117 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
187 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
353 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
236 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
278 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
216 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 ...
5
votes
1answer
415 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
82 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
181 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
655 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
276 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
230 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 ...
3
votes
0answers
57 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
672 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
264 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
133 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
474 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 ( ...