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

learn more… | top users | synonyms (5)

30
votes
4answers
3k 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 ...
-1
votes
0answers
40 views

MVVM & Threads: Which layer should dispatch on the UI thread? [on hold]

I am implementing the MVVM pattern on an iOS native app. Say the model runs something in other thread than the UI one, and notifies about something's completion to the view model, which at the same ...
4
votes
1answer
42 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
41 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 ...
1
vote
2answers
59 views

Many AJAX requests to check domain availabilities [closed]

I've recently developed a website that randomly generates unique names, then checks for their .com availability. In order to do this, I call 3 AJAX requests to a php page where it randomly generates ...
3
votes
1answer
139 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
86 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
75 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
32 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 ...
1
vote
0answers
57 views

Threading strategies for a webservice implementation

If I am building a webservice/Web API for servicing requests, there are 2 threading strategies I can think of. I will explain this in terms of Java (though the question may be relevant for any other ...
-3
votes
1answer
75 views

How do synchronized objects work? [closed]

This is to inform you that I am learning about multi-threading. I recently completed Synchronized method concept. Everything is clear but I am not able to get working of Synchronized block. It seems ...
3
votes
1answer
179 views

How do I prevent a long running SQL query from looking stuck?

If I had a method like: private void someMethod() { runSqlQueryA(); runSqlQueryB(); runSqlQueryC(); } My understanding is this method will be one thread. In weblogic, the thread will ...
1
vote
1answer
116 views

Behaviour of Thread sleep in a single core processor machine?

I'm trying to understand how threading works when using a single core, not hyper-threaded processor. I have two identical console applications running on a machine that has one core CPU and 1 GB of ...
0
votes
2answers
53 views

Built-in the separate thread execution inside of the method or wrap the method by the thread

Let assume, I have some resource and time-consuming code, which I want to arrange as a separate method. In order to optimize the performance, this code should be executed in the separate thread. Now ...
3
votes
1answer
76 views

Design approach to outsourcing a socket in an own thread

I want to extend an existing server written in C++ to be able to communicate with an other server over websockets (e.g. logging or user authorisation purposes). All examples (including the very well ...
2
votes
1answer
54 views

How does condition_variable::notify_one() choose which thread to unblock?

notify_one() of C++ 11 thread library is used to unblock one of the waiting threads. How does it choose which thread to unblock? To begin with, I tried googling but could not find any appropriate ...
0
votes
2answers
113 views

What's the simplest way to deal with events in C in this situation?

I'm writing a text-based game, in C. I want the game to handle NPCs movement and actions in the background, while the user is making his moves. I'd also use time-based events to tell the user when ...
0
votes
2answers
88 views

Multiple threads making call to precompiled library

I have been asked this question in an interview and I thought to take advice from you guys. Say I have a pre-compiled library which references to some function say "strtok". There is no source code ...
0
votes
0answers
34 views

Android Service vs Simple class with thread for network access

I am in quite a dilemma about how to solve my problem regarding network access. I checked this question but it does not really gives a solution for my problem. All of my REST based requests are ...
4
votes
2answers
399 views

How many threads is too many to maintain a chat server?

I'm writing a chat server and client. For the chat server I have 3 "services" all running on their own threads: ConnectionListener that loops over accept, and adds any new clients to a ...
1
vote
3answers
234 views

Can multiple synchronized methods in same object run concurrently

As far as i know when there are multiple synchronized methods(both static and instance) in a class, java allows only one such method to run at a time. But what if a thread acquires lock on an object ...
0
votes
1answer
205 views

pthread versus boost::thread - need to set the thread priority on an ubuntu box

I wrote a class that basically executes a numerical analysis code in a thread using boost::thread. Now I need to specify the thread priority, since we are running a system with near real-time ...
0
votes
0answers
95 views

Is it possible to have multiple threads using Background Workers for different controls within one GUI

In my current project i have a CPU intensive 3D chart that needs to be updated in real time. I have been using background workers for the project and using those, i do all the processing in the ...
4
votes
4answers
169 views

Testing concurrency/thread-safety

A program I have wrote uses multiple threads and I believe my program is thread-safe but how can I really know? I've read a number of examples online and none of them describe how to test the code is ...
0
votes
1answer
132 views

Converting from List<Object> to Array with threads

I have a large (>500.000) list of Objects and I want to convert it a multidimensional array. Until now I am doing this using a for loop, but after some measurements I identified that this is a ...
1
vote
1answer
191 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 ...
3
votes
1answer
294 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 / ...
1
vote
1answer
544 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
53 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
57 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
62 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
66 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()) ...
5
votes
3answers
3k 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 ...
0
votes
1answer
75 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
51 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
69 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
130 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 ...
4
votes
3answers
257 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
152 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 ...
2
votes
1answer
87 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
233 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 ...
4
votes
2answers
203 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
312 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
539 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
3answers
715 views

Const means Thread-safe? [closed]

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
304 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
96 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
256 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
87 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
192 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 ...