Questions tagged [multithreading]

42855 questions
1

votes
1

answer
94

Views

Thread synchronization in C#

in my application I use different threads (one for every active transfer). I would for example want to limit the active tranfers, putting the other coming ones in a queue. For now my solution was checking if there was space for another active transfer, if not I would put the request in a queue list....
Alexietta
1

votes
2

answer
672

Views

Checking every “word” from aaa..a to zzz..z

My program is supposed to be a brute force password cracker (school assignment). The input arguments are as follows.. ./crack threads keysize target The program needs to check passwords of length keysize, but also need to check shorter ones. I am unsure of how to go about writing something that wil...
m96
1

votes
2

answer
450

Views

Will a single task in C# be executed in parallel on a multi-core system? [closed]

I am just finding my way around parallel programming in C# and understood the significance of cores and true parallel programming. But I still have a question: Say I have a long running task does that mean this will be executed using threads from thread pool and in different cores for true parallel...
ckv
1

votes
1

answer
926

Views

Clone an existing ApplicationContext in Spring

I have a multi-threaded application I am trying to write with Spring, right now I am using the new thread scope declaration on my beans and passing the same context into the Runnable class. The threading works fine and I get a new copy of the DAO/Services for each thread so exactly how I want it. Th...
Clarence Liu
1

votes
1

answer
834

Views

Joining task-parallel threads

I know how to join a simple thread to make parent thread wait for them but I don't know how to do it for automatic threads implemented in System.Threading.Tasks namespace . Here's an example . I call two functions in my main function that I want to be executed respectively . Each function has an par...
arman radan
0

votes
0

answer
5

Views

File locks from fcntl to sync dylibs in same host

I am writing a series of plugins for a 3rd party OSX host application, who will have to communicate with each other via shared memory. Each will be located in it's own dylib, and they will thus all be loaded into the same host process. Or not, depending on whether there's one or more host processe...
Carl Colijn
1

votes
2

answer
171

Views

Multi Threading File Saving operation?

I am developing an application which basically stores 2D matrices in memory and performs mathematical operations on them. When I benchmarked my software I found that file reading and file saving were performing very badly. So I multi threaded file reading and this resulted in tremendous boost in per...
Cool_Coder
1

votes
2

answer
334

Views

Accessing dictionary items added by another thread

Here is my code - public partial class MainWindow : Window { ConcurrentDictionary Cache = new ConcurrentDictionary(5, 199); int width = 720; int height = 480; int stride = (width * 3 / 4 ) * 4 + 4; int currentframe = 0; public MainWindow() { InitializeComponent(); Thread t = new Thread(() => { while...
phil
1

votes
2

answer
663

Views

Prevent concurrent callback code from running twice

The following code run inside a new thread. private class SaveUserTask extends AsyncTask { @Override protected Void doInBackground(User... users) { DatabaseHandler dbHandler = new DatabaseHandler(LoginActivity.this); dbHandler.createUser(users[0]); return null; } } The code that construct it and run...
Sandah Aung
1

votes
2

answer
1.5k

Views

Cancel button on Notification to remove Notification

I have a Notification that has a Progress Bar and a Cancel button. I am using Thread to increment the Progress Bar and the Cancel button is supposed to clear the notification. Here's the code for Notification remoteViews = new RemoteViews(getPackageName(), R.layout.customnotification); Intent intent...
Rohan Kandwal
1

votes
1

answer
303

Views

storage and management of overlapped structure in multithreaded IOCP server

Is it good idea to use LINKED LIST to store overlapped structure? my overlapped structure looks like this typedef struct _PER_IO_CONTEXT { WSAOVERLAPPED Overlapped; WSABUF wsabuf; .... some other per operation data .... struct _PER_IO_CONTEXT *pOverlappedForw...
maciekm
1

votes
2

answer
746

Views

Will displaying a UIAlertView in a separate thread stop processing in main thread?

I have an iPad app that makes appointments. If the user happens to overlap an existing appointment, I need to let them know via a UIAlertView. The problem is of course, that the UIAlertView doesn't get displayed until the 'Save' method completes it's processing. I was thinking of using a separate...
SpokaneDude
1

votes
2

answer
243

Views

Is compiled multi-threaded Python affected by the GIL

As the GIL is a lock that surrounds the interpreter does it affect compiled Python? I'm wondering whether it is possible to get past the inherent multi-threading limitations of cpython by simply compiling my python before executing it. Hopefully that makes sense and I'm not missing something obvious...
mattdavis90
0

votes
1

answer
23

Views

What map methods must be synchronized for thread safety?

I have a class which contains a map and this map might be accessed simultaneously from several threads. I create my class as follows: @Autowired public Scheduler() { this.scheduledRunnables = Collections.synchronizedSortedMap(new TreeMap()); } So according to the documentation, to ensure this works...
hochas
1

votes
1

answer
810

Views

Creating a NSManagedObjectContext on a private/background queue: how to do?

I am confused about how to create a MOC on other threads than the main thread. On one hand, in the doc, one can read A consequence of this is that a context assumes the default owner is the thread or queue that allocated it—this is determined by the thread that calls its init method. You should n...
Colas
1

votes
1

answer
1.6k

Views

Split tasks among threads in python

I have python code which reads data as stream (sys.stdin) and then perform some action for each line. Now as volume of data is increasing, i want to split the task among threads and let them work in parallel. Went through the docs and most of them suggest that threads need to poll (eg from Queue) to...
Mohit Verma
1

votes
1

answer
2.6k

Views

Safely disconnecting from boost::signals2

With boost signals (which is now deprecated) I always wrapped connection management and signal invocation with a mutex in order to be thread-safe. Boost signals 2 should give that out-of-the-box. But: According to the Boost Signals2 Thread-Safety documentation, it is possible to disconnect slots fro...
Manuel Barbe
1

votes
2

answer
3.1k

Views

C# program hangs on Socket.Accept()

I created a server "middleman" application that uses sockets and multi-threading techniques (ServerListener is run in a new thread). I found early on that when I would use the Socket.Accept() method, the program would hang indefinitely, waiting for that connection to happen. The problem is, as far...
FeelsLikeANewb
25

votes
2

answer
342

Views

Why does this small Java program make MacOS restart?

Code is as follows Set threads = new HashSet(); Runnable r = () -> { try { Thread.sleep(Long.MAX_VALUE); } catch (InterruptedException e) { e.printStackTrace(); } }; for (int i = 0; i < 20000; i++) { Thread t = new Thread(r); threads.add(t); t.start(); if (i % 100 == 0) { System.out.println(i); } Th...
Koray Tugay
1

votes
2

answer
276

Views

Appengine Python DevServer Module Background Thread 500 Error

I'm on version 1.9.9 of the SDK and I'm having issues with the devserver. I have a manually scaled module with 1 instance. I created a webapp2.RequestHandler for /_ah/start. In that handler I start a background thread. When I run my app in the devserver, the _ah/start handler returns a 200, but /_ah...
Eliezer
1

votes
1

answer
361

Views

Sequential threads that spawn from an event in Android

I have an event that fires within a runnable found within a service. The main runnable is started by a TimerTask. The event within this main runnable should sequentially spawn worker threads. The threads should work in the sequence that they were spawned and go to completion. What is the best w...
user3366176
1

votes
2

answer
1.1k

Views

Network call not happening from a thread in a broadcast receiver

Im a beginnner of android and im trying to build an app that recognizes a missed call and sends the number to be stored in a remote mysql database. The app is able to recognize missed calls but the network calls are not happening. I am not able to run this app in the emulator and so im using a devic...
bukke hari prasad
0

votes
0

answer
21

Views

SQL Server 2016 experiences insufficient memory or sessions exceeds the maximum allowed in the server

On SQL 2016 server , we are getting the stack dump for " insufficient memory or the number of configured sessions exceeds the maximum allowed in the server" This is newly upgraded from SQL server 2014 to SQL 2016 2016 (SP2). Its on VM and has 48 GB memory. When this error happened the Max memory was...
Raja
1

votes
3

answer
445

Views

How to wake thread by condition

I have an activity running, of course, on UI thread and there is another thread running in background and communicating with activity using Handler post method(through looper). When screen is turned of or application is hidden it continues to work. So I need to stop this thread in onPause method and...
djagtorf
1

votes
1

answer
717

Views

To check whether thread's apartment type is MTA or STA?

Is there any way so that i can check the apartment type of thread,whether it is MTA or STA while debugging an application on runtime ? I am working on winforms application in visual studio 2008 IDE.
Mandar
1

votes
2

answer
311

Views

Reentrant Synchronization- Unlocking of called synchronized method

void method1() { synchronized(this) { // Acquires intrinsic lock method2(); } } void method2() { synchronized(this) {} // Acquires same lock due to Reentrant synchronization } First time lock is acquired in method1 which calls synchronized method2 where second time it gets the same lock . Now m...
Javed Solkar
1

votes
1

answer
99

Views

How to execute and receive results from AsyncTasks outside of the main thread?

I have a bunch of AsyncTasks and their callbacks (listener interfaces) that I dont want to have anything to do with the UI thread. Reading the answer here: Android : can AsyncTask return in another thread than UI thread? I am left with the impressin that I can only start AsyncTasks from the UI Threa...
J. K.
2

votes
1

answer
55

Views

How to instantiate multiple threads using the same function C++

Here is function execute(), used for some instructions: void execute() { while (run) { //thread is running if (time % 3 == 0) { // execute instructions when clock is 3 Instruct Instr; uint16_t src1 = 0; uint16_t src2 = 0; int target_cycle = time; while (target_cycle > time) { std::this_thread::sleep...
Flave
1

votes
2

answer
1.5k

Views

QT - force an object to process incoming signals

I am wondering how to tell a QObject to process all signals and call the slots associated with them. Here's the concrete problem I am having, for a better description of the question: My program consists of three Qthreads : Main, Communication and Input. The communication thread handles communicatio...
user129186
1

votes
5

answer
1k

Views

An example that shows the requirement of ThreadLocal usage

As far as I know, In Java, ThreadLocal class enables us to create a virtual thread scope. So a thread can not accesses to another's variable or something else. Could you please give some piece of code that coder needs to use ThreadLocal and after usage of ThreadLocal everything is ok. Thanks.
Nas Ahmet
1

votes
4

answer
281

Views

How can I prevent my UDP keepalive from using 100% CPU?

I have a Runnable that watches for data to send out UDP as well as to send a keep alive every 10 seconds. The process is taking 100% CPU. I tried setting the thread to low priority but didn't seem to make any difference. private Runnable keepAliveRunnable = new Runnable() { long nextSend = 0; byte[]...
John Smith
0

votes
0

answer
19

Views

How to stop function from finishing its code in event loop

I have event loop that runs the function asynchronously. However, that function generates big data so the execution will be a little bit long when the program visits that function. I also implemented a stop button, so the app will exit that function even if the event loop is not yet finish. The prob...
1

votes
2

answer
2k

Views

Concurrent quick sort (multithreading)

I am trying to make quick sort concurrent by using threading. But when i run the code with my threading approach, it only runs the same thread for all the partitions recursively. Here is what I have tried. from threading import Thread import threading import time import thread def qsort(sets,left,r...
yudhveer singh
1

votes
4

answer
38

Views

Understanding deadlock with a simple example

I am working on understanding deadlock basics so I came up with below code. I have two threads acquiring locks in opposite order but they're not deadlocking. When I run it I see all the printouts. What am I doing wrong? public class DeadlockBasics { private Lock lockA = new ReentrantLock(); private...
flash
-1

votes
1

answer
26

Views

ThreadPool pass function as argument

I'm trying to implement my own version of parallel for using https://github.com/Fdhvdu/ThreadPool as the backend thread pool I'm splitting up the task to several slices and launching a thread with the following function: template void launchRange(int id, Callable func, int k1, int k2) { for (int k...
La bla bla
1

votes
1

answer
512

Views

Critical Section inside for loop in Openmp

I have the following code: #pragma omp parallel for private(dist,i,j) for(k=0;k
akshita007
1

votes
2

answer
715

Views

How to make concurrent hash map thread safe with get and put as an atomic operation?

Is my below method thread safe? This method is in Singleton class. private static final Map holder = new ConcurrentHashMap(); public BoundStatement getStatement(String cql) { Session session = TestUtils.getInstance().getSession(); PreparedStatement ps = holder.get(cql); if(ps == null) { // If "ps" i...
john
1

votes
1

answer
2.8k

Views

Kafka Consumers throwing java.lang.OutOfMemoryError: Direct buffer memory

I am using single node Kafka broker (0.10.2) and single node zookeeper broker (3.4.9). I am having a consumer server (single core and 1.5 GB RAM). Whenever I am running a process with 5 or more threads my consumer's threads are getting killed after throwing these exceptions Exception 1 java.lang.O...
Abhimanyu
9

votes
2

answer
237

Views

java 11 HttpClient leads to endless SSL loop

I am using the new java.net.http.HttpClient with the sendAsync method. The HttpClient is inside a Singelton and is created once like so: HttpClient.newBuilder().build() so really nothing special. Those requests can be POST or GET but I don't know which causes the trouble. There are just a few reques...
Zarathustra
0

votes
1

answer
21

Views

C++ threads stack address range

Does the C++ standard provide a guarantee about the non-overlapping nature of thread stacks (as in started by an std::thread)? In particular is there a guarantee that threads will have have their own, exclusive, allocated range in the process's address space for the thread stack? Where is this des...
Curious

View additional questions