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

learn more… | top users | synonyms (5)

-3
votes
1answer
63 views

How do synchronized objects work?

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 ...
0
votes
0answers
79 views

Is it possible to miss a connection?

I'm writing a simple asynchronous tcp server & client program and I am curious if it's possible that the method "waitForConnections" misses a connection because it's still busy with accepting the ...
0
votes
1answer
439 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 ...
4
votes
5answers
515 views

If I use locks, can my algorithm still be lock-free?

A common definition of lock-free is that at least one process makes progress. 1 If I have a simple data structure such as a queue, protected by a lock, then one process can always make progress, as ...
3
votes
1answer
158 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
109 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
48 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
70 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
50 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 ...
5
votes
1answer
480 views

Scheduling a few CPU-intensive tasks

I need to schedule a small number of CPU-intensive tasks to run every so often, reading from shared data and writing to dedicated buffers. I don't necessarily want to roll my own scheduling, but am ...
0
votes
2answers
104 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 ...
8
votes
3answers
8k views

How is multi-threading different in a Java based Web Application vs Stand-alone Java Application

I am fairly new to Java and my experience is limited to Web Based Applications running on a Web Container (Jboss in my case). Am I correct in saying that for Web Applications the web container takes ...
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 ...
1
vote
2answers
863 views

Multi-Threaded JavaScript?

I know, I know--it isn't possible presently BUT my question is this: Would it be possible to write a browser plug in for the major browsers that enables true, multi-threaded JavaScript? It just ...
75
votes
13answers
26k views

What can multiple threads do that a single thread cannot? [closed]

While threads can speed up execution of code, are they actually needed? Can every piece of code be done using a single thread or is there something that exists that can only be accomplished by using ...
4
votes
3answers
2k 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 ...
2
votes
2answers
4k views

High-Load Java Server for Multiplayer

I am making a multiplayer game. Now I am trying to choose the technology to connect the android devices to the server. The clients run on Android, and the game is MMORPG. I would like to write the ...
18
votes
9answers
22k views

Multithreading synchronization interview question: Find n words given m threads

I came across this question: You are given a paragraph , which contain n number of words, you are given m threads. What you need to do is , each thread should print one word and give the ...
0
votes
2answers
79 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
29 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
363 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
131 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
154 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
83 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
143 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
124 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 ...
32
votes
6answers
4k views

Testing multi-threaded race conditions

Reading the comments to this answer, specifically: Just because you can't write a test doesn't mean it's not broken. Undefined behaviour which usually happens to work as expected (C and C++ are ...
7
votes
9answers
4k views

Multithreaded file copy

There is an utility we have which is used to upload files (and perform other operations on the file) to a network shared location. The file size tends to vary from a few mb to 500 mb. A suggestion has ...
5
votes
2answers
8k views

JUnit Testing in Multithread Application

This is a problem me and my team faces in almost all of the projects. Testing certain parts of the application with JUnit is not easy and you need to start early and to stick to it, but that's not the ...
20
votes
3answers
17k views

What is a thread pool?

How would one implement a threadpool? I've been reading on wikipedia for "threadpool" but I still can't figure out what one should do to solve this question (possibly because I didn't quite understand ...
1
vote
1answer
148 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 ...
4
votes
3answers
212 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, ...
3
votes
1answer
244 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 / ...
3
votes
2answers
1k 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, ...
-1
votes
1answer
64 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
3answers
261 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 ...
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 ...
16
votes
5answers
4k views

What are the best resources for learning about concurrency and multi-threaded applications? [closed]

I realised I have a massive knowledge gap when it comes to multi-threaded applications and concurrent programming. I've covered some basics in the past, but most of it seems to be gone from my mind, ...
1
vote
1answer
61 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 ...
5
votes
5answers
4k views

Can multiple CPU's / cores access the same RAM simutaneously?

This is what I guess would happen: If two cores tried to access the same address in RAM, one would have to wait for the other to access the RAM. The second time that each core would try to access ...
1
vote
2answers
222 views

How do I find a good middle way to make this library safe for concurrent operations

I've made a little library called SignalR.EventAggregatorProxy Before I push it into 1.0 state I need to fix so it works safely with concurrent operations. Easiest way is lock all operations but ...
0
votes
0answers
211 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 ...
0
votes
1answer
70 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 ...
2
votes
3answers
279 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 ...
-1
votes
1answer
48 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
67 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
120 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 ...
7
votes
2answers
11k views

How to program thread allocation on multicore processors?

I would like to experiment with threads on a multi-core processor, e.g. to create a program that uses two different threads that are executed by two different processor cores. However, it is not ...
2
votes
1answer
137 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 ...