Skip to main content

Questions tagged [stdthread]

std::thread is a C++11 standard library class which represents a single thread of execution. Threads allow multiple functions to execute concurrently.

stdthread
-4 votes
0 answers
56 views

Unusual Access Violation when joining a thread [closed]

When terminating my program, the many components join their threads and this particular one gives me an access violation when joined along with other components at the same time. The code is simple - ...
SagunKho's user avatar
  • 1,011
0 votes
1 answer
71 views

QProcess and std::thread - Cannot create children for a parent that is in a different thread

I am getting a run-time message QObject: Cannot create children for a parent that is in a different thread. when starting a QProcess in a std::thread. The program runs, but I feel that this message ...
rpsml's user avatar
  • 1,498
0 votes
1 answer
95 views

Virtual memory size increases considerably with thread count

In the below C++ code example, each time the user presses the Enter key, a new thread will be created. The thread waits for 10 minutes and then exits. The thread has a std::string object with some ...
Ajin Pradeep's user avatar
1 vote
1 answer
81 views

C++ Concurrency - memory_order_acquire [duplicate]

#include <atomic> #include <thread> std::vector<int> queue_data; std::atomic<int> count; void populate_queue() { unsigned const number_of_items=20; queue_data.clear(); ...
Rupa's user avatar
  • 110
2 votes
2 answers
69 views

How to spawn a single thread with OpenMP (like a std::thread()) and use "#pragma omp single" and "#pragma omp for" afterwards?

I would simply like to spawn a background thread, like std::thread, but just with OpenMP. Is this possible? If yes, how ist it done? To better explain what I want to achieve, here the C++ Code of what ...
martin7743's user avatar
3 votes
1 answer
121 views

Why should I not pass a lambda with by-reference captures to the std::thread constructor?

I wrote a timer class, but it does not work the way I needed it to. Can anyone tell me what is wrong with this? template<typename D, typename C> class timer { public: timer(D period, C&&...
Andrey's user avatar
  • 41
2 votes
1 answer
170 views

Not able to stop jthread using stop_token

very new to posting here, so apologies if it's in the wrong place. I'm a hobby coder, so my experience is limited and while I learned C++ some years ago, I have to re-learn it periodically. Now is ...
Radiobiscuit's user avatar
0 votes
1 answer
64 views

recv doesn't work in a thread - Windows c++

I'm currently developing a TCP server and I use multi threading, so for this I init a server using a Server.start() which give me a fd like and then I init an infinite loop to accept and start new ...
B0tm4n's user avatar
  • 25
4 votes
3 answers
184 views

What happens with a thread's arguments if thread creation fails?

Imagine I create a thread like this: jthread thr( []( string &&str ) {}, move( str ) ); What happens if the thread creation fails ? Is the string guaranteed to keep its old contents ?
Edison von Myosotis's user avatar
0 votes
1 answer
55 views

c++ thread: wrap thread function in lambda

#include <iostream> #include <thread> class MyClass { public: MyClass(int val) : val_(val) {} int val_{0}; }; void threadFunction(MyClass myObj) { // do ...
Mathieu's user avatar
  • 59
0 votes
1 answer
76 views

c++ thread function accepting object by value: why does std::ref(obj) compile?

#include <iostream> #include <thread> template<int Num> class MyClass { public: MyClass(int val) : val_(val) {} // Copy constructor MyClass(const MyClass& other) : ...
Mathieu's user avatar
  • 59
1 vote
0 answers
171 views

Problem with g++ on Mac using std::thread and exceptions

this is my first question here, so feel free to ask for further information if needed. EDIT: After the bot encouraged me to clarify my problem and state what I'd like to do: I would like to use C++ 20 ...
Philipp Rosendahl's user avatar
0 votes
0 answers
115 views

getting core dump in this simple threading program in C++

I'm new to concurrency in C++. I just tried creating new thread and tried running it. But I'm getting memory fault(coredump) error. Now able to find why it is causing memory fault. When I tried to ...
Elanchezian R's user avatar
0 votes
0 answers
88 views

C++ lambda used in std::thread crash

This my code: std::thread t([](){ int ret = func(); if (ret != 0){ return false; } }); t.detach(); As this code, compiler deduce the lambda return value type is bool, so when ret==0, the ...
wangjs's user avatar
  • 19
0 votes
1 answer
123 views

What is wrong with this C++ multi-threaded program?

I write a multi-threaded C++ program using std::thread that looks like the following: #include <iostream> #include <thread> #include <mutex> #include <condition_variable> using ...
Recursion's user avatar

15 30 50 per page
1
2 3 4 5
42