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.

std::thread is a C++11 standard library type which creates a new thread and runs a function (or other callable object) in that new thread.

Include the <thread> header to use std::thread.

C++20 added std::jthread which automatically .join()s the thread on destruction instead of std::terminate()ing, a generally preferable behavior.

593 questions
0
votes
0 answers

What causes this Visual C++ Debug Error for asio server example?

Update: I am going to use detach since my plan is to shut down the application, so I don't need join. Please correct me if I am wrong. Original question I am following the asioref-1.10.6 example for the TCP server with asynchronous mode. I don't…
Splash
  • 1,288
  • 2
  • 18
  • 36
0
votes
1 answer

std::thread context of execution (c++14)

The problem appear when an in/out variable of a function called by std::thread changes the value during the execution... Function: static int func(stThread_t *&pStThread) Parameters pStThread: It´s a struct that has a pointer to std::thread and…
0
votes
2 answers

Array of threads and attempting to pass multiple arguments to function is not working?

I am creating a program with a dynamic number of threads. I have a vector for the threads (thanks, Mohamad); then I attempt to call a function and pass multiple arguments for the thread of execution. However, my current code gives an error which I…
0
votes
1 answer

std::move of std::packaged_task does not compile (vs2013)

std::move doe's not compile when moving an std::packaged_task object. the errors are: error C2182: '_Get_value' : illegal use of type 'void' error C2182: '_Val' : illegal use of type 'void' error C2182: '_Val' : illegal use of type…
aviyaChe
  • 145
  • 1
  • 9
0
votes
1 answer

GCC-Visual Studio std::thread compiler differences

EDIT: added the compiler errors at the end. First I'll say I have both Visual Studio Express 2013 and CodeBlocks (Mingw w64) set up and running. But I am having a problem with some code compiling with one compiler but not the other and…
Ark.
  • 81
  • 1
  • 4
0
votes
1 answer

How do two or more std::threads operate on the same function?

I am developing a C++ program in which I am processing several pairs of data(arrays and matrices). Due to time requirements, I need to process corresponding pairs in parallel and I am planning to use std::threads for that purpose. Since they will be…
Ali Kavis
  • 3
  • 2
0
votes
0 answers

Deadlock using std::thread and std::condition_variable

I'm investigating an issue where my worker thread deadlocks when I try to stop it. Here's the minimal version that has the problem: #include #include #include #include #include #include…
anorm
  • 2,255
  • 1
  • 19
  • 38
0
votes
2 answers

Is it ok to replace std::thread objects?

From what I could gather in C++ online documentation, assigning to a joined std::thread object should call its destructor and represents a legitimate operation. Is this the case? Here some example to show what I mean: #include #include…
Adrian
  • 2,276
  • 2
  • 19
  • 25
0
votes
0 answers

parallel c++11 program random crashes

I have a problem which I could not solve for a long time now. Since, I don't have more Ideas I am happy for any suggestions. The program is a physics simulation which works on a huge tree data structure with millions of dynamical allocated nodes…
0
votes
0 answers

Moving std::thread and maintaining state

I have a class which maintains a worker thread. It needs to be move constructible as I pass them around and add/remove from arrays, such as: for (...) { Foo foo; foos.push_back(std::move(foo)); } The class setup looks like…
Dan Halliday
  • 725
  • 6
  • 22
0
votes
1 answer

Compiler error C2064 in functional when try to initialise a std::thread in a class constructor

I am writing a class which uses a thread and I wanted to try the new C++11 std::thread. I am compiling with Microsoft Visual Studio Pro 2013 v12.0.31101.00 Update 4. The update is from Nov 2014 so is fairly up-to-date. I can use std::thread for…
Angus Comber
  • 9,316
  • 14
  • 59
  • 107
0
votes
1 answer

Minimum amount of work it is worth spawning a new thread

How can I estimate the minimum amount of work it is worth spawning a new thread? I'm principally interested in C++11 std::thread. Long explanation. I was trying to speed up our application so I went on parallelizing a low level function, that…
Paolo M
  • 12,403
  • 6
  • 52
  • 73
0
votes
1 answer

Multithreading behaviour change when linking a static library to a program

I have been developing an efficient sparse matrix solver that uses the concept of multithreading (C++11 std::thread) for the past year. Doing a stand alone test on my code works perfect and all expectations were exceeded. However, when linking the…
Anas
  • 359
  • 1
  • 5
  • 14
0
votes
1 answer

Terminate current thread

How can I cleanly terminate the current child std::thread in C++11? The decision to terminate is made at a function call depth of 4 or 5 from the main thread method so I don't want to check whether I should terminate at each return. I have looked at…
Sidharth Mudgal
  • 4,234
  • 19
  • 25
0
votes
1 answer

std::thread class method errors

I'm trying to create threads to run row-by-row on a grid-based terrain (i'm not asking if this is efficient, I'm just testing something out) but I keep coming across 2 errors: first being that if I don't pass the function as…
Dillanm
  • 876
  • 12
  • 28