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 8065643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:44:00+00:00 2026-06-05T11:44:00+00:00

I have a problem that has been bothering me for a while. Each child

  • 0

I have a problem that has been bothering me for a while. Each child thread in my project is running correctly and does what it is supposed to do with the exception of beginning the thread with Last Error set at 87.

87 means invalid parameter according to Win32 System errors. Since LastError is thread-specific, and since from the very first line of the ThreadProc function it appears to be set the only thing I can deduce is that the ThreadProc function itself is somehow wrong syntactically(?).

My OS is Windows 7 x64 and the compiler is gcc version 4.6.2
I have made a small example program which in my system starts the child thread with error 87 set.

#include <windows.h>

DWORD WINAPI THREAD_FUNCTION(LPVOID t)
{
    printf("In the child thread: Last Error is %lu\n",GetLastError());
    return 0;
}

typedef struct thread_data
{
    //just an id for example's sake
    uint32_t id;
}thread_data;

int main()
{
    HANDLE thread;
    thread_data d;
    d.id = 1;
    printf("Main thread start:Last error is %lu\n",GetLastError());
    //create the thread
    thread = CreateThread(NULL,0, (LPTHREAD_START_ROUTINE) THREAD_FUNCTION,(LPVOID)&d,0, NULL);
    //wait for it
    WaitForSingleObject(thread,INFINITE);
    CloseHandle(thread);
    printf("Main thread finish: Last error is %lu\n",GetLastError());
    return 0;
}

This outputs:

Main thread start:Last error is 0
In the thread: Last Error is 87
Main thread finish: Last error is 0

I assume it is an error of the way I call the thread and pass data to it but I can’t deduce this error by reading the documentation. Any ideas?

  • 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-06-05T11:44:01+00:00Added an answer on June 5, 2026 at 11:44 am

    The return value of GetLastError() in your example is meaningless. Calling GetLastError() is only valid immediately after calling a Windows API function that sets the last error value (the MSDN documentation for state whether a given function does so or not).

    In your thread routine you are calling GetLastError() without calling any Windows API functions that would set it, so its return value doesn’t reflect any error that your code caused so it means nothing to you.

    It’s possible that the value of GetLastError() are a newly started thread is completely meaningless – that it’s just random that it is set to 87. More likely there is some code that executes during thread setup that generates the 87 error. If this code was build in Visual Studio or run on a different version of Windows you may get a different value. But no matter what it’s not something that you can control or rely on or even need to care about.

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

Sidebar

Related Questions

I have a problem that has been stumping me for a while, I wrote
I have a problem that has been bothering me now for a few days.
Hi I have some problems that has been bothering me for a week. I
I have a problem that has been bugging me all day. In my code
I have a problem that has been nagging me for some time now and
I have a problem that has been consuming me for days. I have a
I have a problem that is and has been perplexing me for hours. I
This is a problem that has been eating at me for a while, and
I have a problem that has been spoiling the way I want to do
I have a problem that has been a thorn in my side for nearly

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.