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

  • Home
  • SEARCH
  • 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 6900347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:32:05+00:00 2026-05-27T07:32:05+00:00

I have a small question about threading in Windows. I have the following code

  • 0

I have a small question about threading in Windows. I have the following code :

main.cpp

int     main(int ac, char **av)
{
  std::vector<Mthread *>    mythread;
  std::list<std::string>    stack;
  DWORD     id = 0;

  stack.push_back("Maison");
  stack.push_back("Femmes");
  stack.push_back("Fetes");
  stack.push_back("Voitures");
  stack.push_back("Nounours");
  while (id != 5)
  {
      mythread.push_back(new Mthread());
      mythread[mythread.size() - 1]->initThread(&stack, id);
      id++;
  }
  id = 0;
  while (id != 5)
  {
      WaitForInputIdle(mythread[id]->getThread(), INFINITE);
      id++;
  }
  return (1);
}

and Mthread.cpp who is creating my Mthread class.

Mthread::Mthread() {}

Mthread::~Mthread() {}

HANDLE      Mthread::getThread(void) const
{
    return (this->thread);
}

bool        Mthread::initThread(std::list<std::string> *list, DWORD ID)
{
    this->save = list;
    this->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Mthread::ThreadFunc, (LPVOID)list, 0, &ID);
    if (this->thread == NULL)
    {
        std::cout << "Erreur lors du lancement du thread" << std::endl;
        return (false);
    }
    else
    {
        return (true);
    }
}

void        Mthread::ThreadFunc(LPVOID list)
{
        std::cout << " is launch" << std::endl;
}

The code is working, but I have a small problem : no string is written on the terminal.
But, if I change my code to :

bool        Mthread::initThread(std::list<std::string> *list, DWORD ID)
{
    this->save = list;
    this->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Mthread::ThreadFunc, (LPVOID)list, 0, &ID);
    if (this->thread == NULL)
    {
        std::cout << "Erreur lors du lancement du thread" << std::endl;
        return (false);
    }
    else
    {
        std::cout << "OK" << std::endl;
        return (true);
    }
}

Well “OK” and “is launch” is written 5 times on the terminal. I don’t understand why.
When I pass a small string a to cout it seems to be working, but when I don’t nothing is written.

  • 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-27T07:32:05+00:00Added an answer on May 27, 2026 at 7:32 am

    Before terminating, your program should wait until the threads have finished their job. On windows, take a look at WaitForMultipleObjects.

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

Sidebar

Related Questions

I have a small question about using jquery. I have the following code: <html>
Another small question about STL: i have Dictionary: map <string,vector <Wordy> > Dictionary; using
I just have a small beginners question, and it's about the code below. I
I'm using BerkeleyDB to develop a small app. And I have a question about
A small - little question. I have seen many application having buttons like following.
I'm writing a small webapp in Grails and I have the following question regarding
I have small question about pdp-11(simulator), I have this command (it begins from the
I have small design question about html.DropDownListFor() How can I change width of html.DropDownListFor()
I have a small question about static variable and TypeObjects. I use the API
I have a small question about structures with the LayoutKind.Explicit attribute set. I declared

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.