Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6669579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:09:59+00:00 2026-05-26T03:09:59+00:00

With win32 threads I have the straight forward GetExitCodeThread() that gives me the value

  • 0

With win32 threads I have the straight forward GetExitCodeThread() that gives me the value which the thread function returned. I’m looking for something similar for std::thread (or boost threads)
As I understand this can be done with futures but how exactly?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T03:10:00+00:00Added an answer on May 26, 2026 at 3:10 am

    See this video tutorial on C++11 futures.

    Explicitly with threads and futures:

    #include <thread>
    #include <future>
    
    void func(std::promise<int> && p) {
        p.set_value(1);
    }
    
    std::promise<int> p;
    auto f = p.get_future();
    std::thread t(&func, std::move(p));
    t.join();
    int i = f.get();
    

    Or with std::async (higher-level wrapper for threads and futures):

    #include <thread>
    #include <future>
    int func() { return 1; }
    std::future<int> ret = std::async(&func);
    int i = ret.get();
    

    I can’t comment whether it works on all platforms (it seems to work on Linux, but doesn’t build for me on Mac OSX with GCC 4.6.1).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been testing inline function calls in C++. Thread model: win32 gcc version
I have a library that I'm writing which processes keystroke events using the Win32
How can I determine if a Win32 thread has terminated? The documentation for GetExitCodeThread
i am using Win32 API. i have a thread in c and want to
I have a C++ Win32 application that was written as a Windows GUI project,
I have a window form application, and it has multiple threads running that would
I have a delphi (Win32) web application that can run either as a CGI
I have an array of Win32 event handles that I'm waiting on using WaitForMultipleObjects().
I have a program that spawns 3 worker threads that do some number crunching,
I have thread exception handler which saves the exception stack trace and should close

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.