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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:49:54+00:00 2026-05-23T16:49:54+00:00

I’m attempting to run a part of my program in a thread and getting

  • 0

I’m attempting to run a part of my program in a thread and getting an unusual result.

I have updated this question with the results of the changes suggested by Remus, but as I am still getting an error, I feel the question is still open.

I have implemented functionality in a dll to tie into a piece of vendor software. Everything works until I attempt to create a thread inside this dll.

Here is the relevant section of the DLL:

extern "C" {
__declspec(dllexport) void __cdecl ccEntryOnEvent(WORD event);
}

to define the function the vendor’s software calls, then:

using namespace std;

HANDLE LEETT_Thread = NULL;
static bool run_LEETT = true;
unsigned threadID;
void *lpParam;

int RunLEETTThread ( void ) {
    LEETT_Thread = (HANDLE)_beginthreadex( NULL, 0, LEETT_Main, lpParam, 0 , &threadID );
    //LEETT_Thread = CreateThread ( NULL, 0, LEETT_Main, lpParam, 0 , NULL );

    if ( LEETT_Thread == NULL ) 
        ErrorExit ( _T("Unable to start translator thread") );

    run_LEETT = false;  // We only wish to create the thread a single time.
    return 0;
}

extern "C" void __cdecl ccEntryOnEvent(WORD event ) {
    switch (event) {
    case E_START:
        if ( run_LEETT ) {
            RunLEETTThread ();
            MessageText ( "Running LEETT Thread" );
        }
        break;
    }

    WaitForSingleObject( LEETT_Thread ,INFINITE);
    return;
}  

The function is declared as

unsigned __stdcall LEETT_Main ( void* lpParam ) {

LEETT_Main is about 136k when compiled as a stand alone executable with no optimization (I have a separate file with a main() in it that calls the same function as myFunc).

Prior to changing the way the thread is called, the program would crash when declaring a structure containing a std::list, shown here:

struct stateFlags {
    bool inComment;    // multiline comments bypass parsing, but not line numbering
    // Line preconditions
    bool MCodeSeen;  // only 1 m code per block allowed
    bool GCodeSeen;  // only 1 g code per block allowed

    std::list <int> gotos; // a list of the destination line numbers
};

It now crashes on the _beginthreadex command, tracing through shows this

    /*
     * Allocate and initialize a per-thread data structure for the to-
     * be-created thread.
     */
    if ( (ptd = (_ptiddata)_calloc_crt(1, sizeof(struct _tiddata))) == NULL )
            goto error_return;

Tracing through this I saw a error 252 (bad ptr) and ultimately 255 (runtime error).

I’m wondering if anyone has encountered this sort of behaviour creating threads (in dlls?) and what the remedy might be. When I create an instance of this structure in my toy program, there was no issue. When I removed the list variable the program simply crashed elsewhere, on the declaration of a string

I’m very open to suggestions at this point, if I have to I’ll remove the idea of threading for now, though it’s not particularly practical.

Thanks, especially to those reading this over again 🙂

  • 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-23T16:49:55+00:00Added an answer on May 23, 2026 at 4:49 pm

    Threads that use CRT (and std::list implies CRT) need to be created with _beginthreadex, as documented on MSDN:

    A thread in an executable that calls the C run-time library (CRT)
    should use the _beginthreadex and _endthreadex functions for thread
    management rather than CreateThread and ExitThread;

    Is not clear how you start your thread, but it appears that you’re doing it in DllMain which is not recommended (see Does creating a thread from DllMain deadlock or doesn’t it?).

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't

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.