Click here to Skip to main content
15,890,282 members
Everything / Multi-threading

Multi-threading

multi-threading

Great Reads

by Eric Ouellet, Sani Huttunen
Fast implementations of permutation algorithms
by Piotr Grygorczuk
Enable C++11 multithreading features in GCC for FreeRTOS
by Petrov Vladimir
Starting Threads in MFC and Win32 and some handling samples
by ObiWan_MCC
A C# SMTP server (receiver).

Latest Articles

by Piotr Grygorczuk
Enable C++11 multithreading features in GCC for FreeRTOS
by Oleg_100
Synchronize access to multiple objects by name (string)
by ls6777
Task monitor for multi-threaded embedded systems
by Eric Ouellet, Sani Huttunen
Fast implementations of permutation algorithms

All Articles

Sort by Updated

Multi-threading 

28 Mar 2024 by RainHat
In the Level1 class change: public string Result; to: private volatile string _result; public string Result { get { return _result; } set { _result = value; } } This should make sure that reads/writes to...
28 Mar 2024 by Member 14623639
I have 2 classes where Class 1 checks for value change in Class 2(Level1). This is the code in Class 1 lvl1 = new Level1(); log.Info($"[{symbol}] Level 1 initialized."); lvl1.Request(symbol); string level1Result = string.Empty; while (true) { ...
30 Oct 2023 by Member 16127436
const char on = 1; int iResult = setsockopt(udp_socket, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); if (iResult != NO_ERROR) { std::cerr
5 Aug 2023 by Graeme_Grant
As @OriginalGriff points out, you can grind your system to a crawl. You could still use TPL[^] which uses a thread pool. It will manage the load for you based on the number of CPU cores. To do this, I would write the processing as a plugin DLL...
4 Aug 2023 by Shrikant_Yadav
Hi Team, I need to convert millions of image to a particular format using third party library. The library provide static functions to convert so I cant use multithreading or parallel.foreach because the library is processing one file at a time....
3 Aug 2023 by OriginalGriff
If the third party is using static methods, then a second Process environment is the simplest (and probably only) alternative - you can do it fairly easily using the Process class to activate an exe and it gets a separate environment even if the...
1 Jul 2023 by Weird Japanese Shows
Hello guys, I've searched online , some say static functions are safe and others say the opposite. I'm quite confused. When thinking logically , they should be safe. But I need to be sure. The function I'm talking about doesn't have interact...
1 Jul 2023 by Member 16041662
Hi, @Richard Deeming "The method is thread-safe" or "The method is not thread-safe" - I think the point is very different here. Since there is no state maintened here (in this class, in this method),The method is thread-safe. Although the...
30 Mar 2023 by Piotr Grygorczuk
Enable C++11 multithreading features in GCC for FreeRTOS
29 Jan 2023 by Oleg_100
Synchronize access to multiple objects by name (string)
12 Nov 2022 by ls6777
Task monitor for multi-threaded embedded systems
11 Oct 2022 by Eric Ouellet, Sani Huttunen
Fast implementations of permutation algorithms
11 Sep 2022 by Mark Pelf
Tutorial article on Observer pattern in C#
11 Sep 2022 by Member 14969632
I have this multithreading (concurrent queue) C++ code where a single consumer executes tasks submitted to the concurrent queue by multiple producers. Assuming that the consumer can handle events faster than that the producers can produce them,...
11 Sep 2022 by Greg Utas
Writing correct multithreaded code is hard, and debugging it is even harder, which is why I advocate a far less error-prone approach[^] in which each thread runs unpreemptably (locked) and yields in its thread loop after completing one or more...
10 Sep 2022 by Rick York
I would start by debugging the locking code. One way you can do this using output messages and this usually called "printf debugging" since the implementations usually used printf. What I would do is add an output statement similar to what you...
6 Sep 2022 by Michael Chourdakis
This class allows math between any size big number, as long as your available memory can handle it.
19 Jul 2022 by Graeme_Grant
There is a simpler version using Data Binding[^] and will simplfy your code. Typically, DataBinding is used with the MVVM pattern but can be used with code-behind. Below is a hybrid code solution - not my ideal choice. What I am suggesting is...
19 Jul 2022 by abdou_31
I'm trying to create and start a new progressBar every click action on button start that exist in the new TabItem ( after clicking on the "+") , so the goal is to run multiple progressBar in the same time , these progressBar will be created on...
14 Jun 2022 by Greg Utas
Cleaving the Gordian knot of thread safety
20 Mar 2022 by sridhar vattam
I am facing a strange issue where my UDP socket that was earlier bound to a port is not unbinding from the port when I call closesocket(). The API call doesn't return any error but netstat command and TCPView app still show that port is still in...
11 Mar 2022 by Mark Pelf
Discussion on proper method to check for null-value and raise Event in C#
1 Mar 2022 by Uladzislau Baryshchyk
An overview of multithreading in C#
22 Feb 2022 by Member 15390900
Can someone help me achieve thread - safe code of the following code: without using mutex or semaphores or synchronous block. Locking and Unlocking of Resources arranged in the form of n-ary Tree - GeeksforGeeks[^] Calling lock or unlock from...
22 Feb 2022 by I_M_R
Hello, the purpose of using mutex and semaphores are sharing a resource between threads and or processes. In multithread application without using mutex or semaphores one can not reserve that resource into the thread first getting permission and...
27 Jan 2022 by Shun Huang
Use Python to build atomic binary trees
16 Dec 2021 by AlexeyAB
Atomic operations and C++11 memory barriers and assembler instructions generated on x86_64 CPUs
11 Nov 2021 by Richard Deeming
No, static functions are not inherently thread-safe. Even your simple example isn't. Assuming both intvariable and stringvariable are supposed to be updated at the same time, another thread could observe the state of c1 between the two...
17 Oct 2021 by Petrov Vladimir
Starting Threads in MFC and Win32 and some handling samples
12 Oct 2021 by Greg Utas
You could use an atomic[^] rather than a mutex. That's the only thing I can think of that's faster. The entire tree must be locked because it's in a transient state until all of the ancestors have been updated. When using an atomic, a thread...
11 Oct 2021 by Richard MacCutchan
The web page already has some suggested solutions, so follow those.
22 Sep 2021 by Matthew Menard
I have a windows form that has (among other things) a Start and a Stop button. If the Start button_click code takes too long, I'd like to press the stop button (or some other event) that will allow me to stop that code from completing. The...
22 Sep 2021 by Patrice T
Quote: The question is about not having to wait for that code to complete before the UI thread will allow the processing of the Stop button_click code. Short answer: you need to move the long job in another thread. The UI thread is what makes...
22 Sep 2021 by OriginalGriff
You can't stop the UI thread doing a long operation with a button, because the button click will not be processed until the long running job has completed. The only way to do it is to move the code to a different thread, but then you can't...
22 Sep 2021 by Dave Kreskowiak
Yeah, this isn't a case where you get to do something simple and everything just works. This is a case of completely redesigning what I think is your small app from the ground up with threading in mind. ALL controls can only be accessed from...
26 Aug 2021 by Jie Chen
I have to deal with a vector containing around 30 million elements, as a result it will return another vector containing around 55 million elements. I decide to go with multithreading. I created a few threads and each thread will handle a...
26 Aug 2021 by KarstenK
Every thread needs some overhead and system resources, so it also slows down performance. Another problem is the so called "thread explosion" when MORE thread are created than cores are on the system. And some waiting threads for the end of other...
25 Aug 2021 by OriginalGriff
We can't help you based on so little information: but from what I read, std::Vector is thread safe* - which probably means that it has internal locking which would seem to confirm the results you are getting. If the methods include internal...
25 Aug 2021 by CPallini
Maybe your threads run on a single core. See, for instance multithreading - C++ run threads on different cores - Stack Overflow[^].
20 Jul 2021 by Dasisqo
Thread is slower, timeout is set to 13 seconds What I have tried: for i in range(400): try: thread=consumer(quee) thread.setDaemon(True) thread.start() thread.excepthook() except: print "Working only with %s threads"%i...
20 Jul 2021 by k5054
Python is limited by the Global Interpreter Lock (GIL), which only allows one thread to execute at a given instance. This means that threading does not reduce program run times, regardless of how many cores your system has. There's a Stack...
20 Jul 2021 by Dave Kreskowiak
Creating 400 threads does nothing but slow your workload down. The system can only execute the same number of threads as you have cores in your CPU, usually 8 or less unless you have a higher-end CPU. So, creating 400 threads is pointless. There...
20 Jul 2021 by Dasisqo
for i in range(400): try: thread=consumer(quee) thread.setDaemon(True) thread.start() thread.excepthook() except: print "Working only with %s threads"%i break
20 Jul 2021 by Dasisqo
I am very much new to coding python script, i wrote a code in python where the functions can scan a list of remote target but the threads dies quick, The problem is that the thread dies and code ends before the scan is entirely complete. What I...
20 Jul 2021 by Richard MacCutchan
You need to ensure that the main thread of your program does not terminate while child threads are active. See threading — Thread-based parallelism — Python 3.9.6 documentation[^]. [edit] Note also that trying to run 400 threads together will...
10 Jul 2021 by aakar
We are calling a Rest API URL via the HttpWebRequest / HttpWebResponse method using IDs that are already stored in a database table. We am currently using a for each loop to iterate through each of the IDs fetched in a DataTable and then making a...
15 Apr 2021 by DeepsMann
Hye,1. I have to program a server which can listen multiple clients on a single port (say 8080).2. Once connection is established with a client, communication starts between client and server. Client sends - Server Receives, then Server sends - Client receives.3. If multiple Clients are...
30 Mar 2021 by AlexeyAB
Smart pointer that makes any object thread-safe for any operations, with the performance equal to that of optimized lock-free containers
27 Mar 2021 by The Sun God
How to speed up your game in Pygame
27 Feb 2021 by honey the codewitch
Using a popular RTOS to enable easy multithreading on your IoT gadgets
25 Feb 2021 by honey the codewitch
Take a page from .NET and enjoy an easy way to safely pass information between threads on an ESP32
16 Feb 2021 by lukeer
Hi forum, searching through the internet gave me the impression that I lack the right search terms for my problem. I may not even know enough python to ask the right question. But I trust in you. I would like to have a python program do its...
16 Feb 2021 by lukeer
Finally opted for blinker[^] for an event system since flask used it anyway. Thank you all.
11 Feb 2021 by markkuk
Quote: Does python even run an event loop that the humble programmer can use and I am too blind to find it? No, unless you add such a loop by yourself or use a library/framework that sets up an event loop for you. By itself, Python is a...
8 Feb 2021 by Richard MacCutchan
See threading — Thread-based parallelism — Python 3.7.9 documentation[^].
25 Nov 2020 by Mladen Janković
Data structure that allows items to be scheduled for processing based on the tags that define item hierarchy
25 Jul 2020 by Member 13257407
Quote: 1. Create class of SalesPersons as a thread that will display fives sales persons name. 2. Create a class as Days as other Thread that has array of seven days. 3. Call the instance of SalesPersons in Days and start both the threads 4. suspend SalesPersons on Sunday and resume on...
25 Jul 2020 by BPiyush
class SalesPerson implements Runnable { private String[] salesPersonName = { "sp1", "sp2", "sp3", "sp4", "sp5", "sp6", "sp7", "sp8" }; private static boolean stopFlag = true; Thread th; public SalesPerson() { super(); th = new...
18 Nov 2019 by Michael Adaixo
Parallelizing ray tracing in C++
13 Nov 2019 by Richard MacCutchan
Probably because of the number of threads and the waits created by calls to System.out.print. Remember a high priority thread will only be selected for execution when it is waiting, and no higher priority thread is waiting. But if thread b has just called System.out then it is in a wait state...
13 Nov 2019 by Member 14654526
In this code, I give the thread b (that prints b) the highest priority, but when I run the program still ends with a series of "b". What is the reason for this? This code is made by my Prof software, but he doesn't know the answer as well. It is only used to show how multithreading is used. The...
13 Nov 2019 by pdoxtader
A multithreaded server class that accepts multiple connections from a provided client class. Each client can send and receive files and text (byte data) simultaneously along 250 available channels.
9 Aug 2019 by sapanagarud
We are using the following code. In base function (onfinishes), if I change JobSummaryobj.filename, sometimes the updated value of filename is not getting passed to launchRequest. Can someone please suggest what to do? internal virtual onfinishes(object sender, EventArgs args)...
8 Aug 2019 by OriginalGriff
I don't have your classes, but a quick test with "abstracted code" from yours: private void DoIt() { var backGroundWorker = new BackgroundWorker(); backGroundWorker.DoWork += (sender, aventArgs) => launchRequest(aventArgs.Argument as MyClass); backGroundWorker.RunWorkerAsync(new...
17 Jul 2019 by ireland94
This program demonstrates the methodology needed for by directional messaging between a Java FX foreground and 1 or more background threads.
12 May 2019 by Gerry Schmitz
timer - What is the best way to repeatedly execute a function every x seconds in Python? - Stack Overflow[^]
28 Apr 2019 by Rick York
I wrote a library and utility to do exactly this many years ago. It was for event message logging. I ended up using a big buffer in shared memory to hold the logged message data and then I had a separate process that monitored the shared memory and wrote it to a file periodically. We used a...
28 Apr 2019 by dj4400
Hi, I have several threads in a C application and i want them to write to a single log file without blocking their run. I probably need to do a worker thread which gets signaled by each thread when it wants to write to the file and then write the data which it got from the signaling thread ...
15 Apr 2019 by Michael Chourdakis
Use Windows new ThreadPool through a single C++ 11 class
10 Apr 2019 by #realJSOP
0) Create a model class that represents your error info (all the properties you want to save). 1) Create a class derived from List to hold the objects as they are created. 2) As the files are processed, and errors are encountered, create a new instance of your ErrorObject model,...
10 Apr 2019 by oronsultan
Hey guys, In our office we are working on large development of data processing. The purpose of the project is to receive a large amount of text files via FTP servers, and then execute on each file certain validations and at the end of the process to insert all the data into the SQL server. ...
10 Apr 2019 by Gerry Schmitz
You're going to be "i/o bound"; multiple threads won't help. Since your data is so simple, you could have ONE process; one CSV file; and one "bulk" loader that eliminates the overhead of "building data rows".
27 Mar 2019 by Maciej Los
Solution #1 by OriginalGriff[^] is excellent and explains in details how to use timer. I wanted to move your focus to these things: 1) possible Sql Injection[^] Never use commands like this: string sqlImage = "select MemberImage FROM Members WHERE MemberCode =" + MemberCode + ""; Instead of...
27 Mar 2019 by ahmed_sa
Problem I need to execute function retrieve image every 10 second by using timer control i already put timer control on windows form but how to run and execute this function in timer every 10 second . meaning i need every 10 second refresh and executing function below I work on windows...
27 Mar 2019 by OriginalGriff
Set the timer Interval to 10 seconds: 10000 Handle the Timer Tick event Start the timer. In the tick handler, call your method.
25 Jan 2019 by David Lafreniere
Simplify passing data between threads using this multithreaded, portable C++ asynchronous callback framework
29 Dec 2018 by Member 11112814
To learn well "Multithreading" I have three buttons, two text boxes and a picture box on a form, each of the three doing completely different things (adding, subtracting and showing pictures). The first time I tried this programm I used the sub: Me.CheckForIllegalCrossThreadCalls = False I...
28 Dec 2018 by OriginalGriff
Invoke and CheckForIllegalCrossThreadCalls are only relevant when you try to access a Control from a thread other than your original UI thread: if you access them from within a thread that you create, then you should use Invoke - which moves the code back to the original UI thread. That has...
16 Dec 2018 by MehreenTahir
This article will help you get started with concurrency and will also introduce you to the features C++ has to support concurrent programming.
13 Dec 2018 by TheBigBearNow
So far I haven’t had luck with my loading gif image when I am loading/checking my database connection I click my login button and I get no errors in my login I start my gif but I also start it in the dowork and progress section im not sure which section is actually right I know not to mess wih...
13 Dec 2018 by Gerry Schmitz
Yes; you display the (new) .gif in the "ProgressChanged" handler (because it runs on the caller's UI thread versus DoWork which "is" the background worker thread). And you have to call "ReportProgress" (to invoke ProgressChanged) from DoWork; it doesn't run by itself.
11 Dec 2018 by TheBigBearNow
Hello all, I have a C# WPF application with a database of users. I have it so a user with the correct info can login and depending if they are an Admin or a Customer it will take them to their appropriate menu. Now I want to have a loading .gif while the program is checking the database for the...
11 Dec 2018 by TABiSH777
Hi, you are on right track, you could use Backgroundworker for this purpose with ease, just remember some thing while working with multithread is that, we cannot access UI elements directly from another thread. And as entire code that's executed in Backgroundworker is in another thread we cannot...
7 Dec 2018 by maysam_p82
Hi everyone . I'm going to write a windows service in python 27. There is a built-in function that mosaic picture tiles named arcpy.mosaicmanagement() . I want to give the function to a thread to work simultaneously. I have two problems: 1- I could run the program as a service in Windows, and...
13 Oct 2018 by Member 14016042
hello!!! I want to Create a program that receives a number N as an argument and starts N threads each displaying one of a number from 1 to N synchronously (with named or anonymous semaphores of choice) to produce an ordered sequence (12 ... N) *. here is my code int N; void* f0(int k, sem_t...
13 Oct 2018 by Rick York
Try pthread_create( &pid[m], NULL, f0, 0 ); When passing a pointer to a function the arguments are not included.
12 Oct 2018 by KarstenK
Really strange that the first error is at this line. The compiler should complain already on: sem_t mutex[N]; This code shuld do the job sem_t *mutex = malloc( sizeof( sem_t ) * N ); //at the ende free( mutex ); Tip: set the warning level higher. This warnings are helping you to write good code :-)
11 Oct 2018 by Member 14016042
I want to create a program that receives a number N as an argument and starts N threads each displaying one of the numbers from 1 to N synchronously, to produce an ordered sequence (12 ... N) *. Where, it is necessary to use one and the same function executed by all threads and pass the number...
11 Oct 2018 by CHill60
If the code you have posted as a solution is genuinely the code causing the error then try changing sem_wait(& mutex[N-1]); to sem_wait(&mutex[N-1]);
11 Oct 2018 by Member 14016042
Sorry I copied the wrong code. #include #include #include #include #include //#include // pour les threads #include // pour les semaphores #include // pour les flags O_CREAT, O_EXCL, ... //...
11 Oct 2018 by OriginalGriff
mutex is declared as part of your main function: int main(int argc, char *argv[]) { N = atoi(argv[1]); sem_t mutex[N]; which makes it a local variable - its scope is limited to the set of curly brackets which most recently enclose it - the main function itself. And then you try to...
30 Aug 2018 by Mohibur Rashid
You need to have One extra threads. * Writer, that writes data into file. * You need to have Queue, Worker thread will push data into queue * Both Queue will have to be thread safe. * Each worker thread will generate it's own data and push to a queue. * Writer thread will pop data from Queue...
30 Aug 2018 by PRABAL VARSHNEY
I am looking for an example which creates multiple threads and all threads are writing the data into single file. It should be in continues loop. If file size are 1 KB then stop the program. What I have tried: I have tried creating multiple threads but I am not able to write data in a single...
30 Aug 2018 by Rick York
In my opinion, having all the threads write to the same file is unnecessarily complicated. I would make a 1KB buffer and a custom routine to write your data into it with a mutex or critical section to control access. Your threads can write into the buffer until its full at which time the...
15 Aug 2018 by Member 10844632
Hi,I have a tcp sender that send large file over tcp.I have a receiver that receive the files and save them to disk.It work great for one file, for multiple files it does not work!I am googleing a few days, went over almost all articles and did not find a solution.I would VERY...
1 Aug 2018 by vudangngoc
Synchronization is slow, why and how to do better?
27 Jul 2018 by nchamberlain
The Sleeping Barber problem, a classic inter-process communication problem, can be studied and explored more easily using tools such as the Concurrency Explorer than using standard parallel or asynchronous coding techniques.
9 Jul 2018 by AlwaysLearningNewStuff
INTRODUCTION I am buidling in-proc COM server to be consumed by VB6 client. COM server needs to use blocking function[^]. This means that the VB6 GUI would be blocked until function retrieves the result, which is unacceptable. Therefore I will use the function in a worker thread, and notify...
6 Jul 2018 by KarstenK
You are NOT only marshalling the interface, but the object and all related obejcts and their memory. That wont work!!! You need to create the instance of the object in the worker thread and do the work. Best is to provide some output memory for the results which the worker thread must write. ...
22 May 2018 by Pawel Wzietek
Synchronous/asynchronous control via multiple interfaces with command queuing