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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:22:02+00:00 2026-06-11T11:22:02+00:00

I require the use of LoadLibrary and GetProcAddress to call functions from some dlls

  • 0

I require the use of LoadLibrary and GetProcAddress to call functions from some dlls (which plug into my app), but I don’t want them to be able to hang my program by containing an infinite loop or hanging themselves, so I’m trying to use boost::thread (no experience) to circumvent that. However, if a function does hang, I crash with ACCESS_DENIED (0x00000005) when calling FreeLibrary to clean up.

Here’s a minimal DLL (mydll.dll) that reproduces the problem:

extern "C" {
    void __declspec(dllexport) foo() {
        for(;;); //<-- infinite loop
    }
}

And here’s a minimal cpp that crashes. I’ve left out error checking for brevity, but I can assure you no errors are given:

#include <boost/thread.hpp>
#include <iostream>
#include <windows.h>

int main() {
    using FuncType = void (*)();

    HMODULE dll = LoadLibrary("mydll.dll");

    FuncType func = (FuncType)GetProcAddress(dll, "foo");

    boost::thread thr = [func] {func();};

    if (!thr.timed_join(boost::posix_time::seconds(1))) {
        std::cout << "Timed out.";
        //thr.detach();
        FreeLibrary(dll);
    }

    for (;;);
}

Upon running this, “Timed out.” is printed and the call stack (gdb on CodeBlocks) at the crash is as follows:

#0 00000000 0x6c1c1214 in ??() (??:??)
#1 0040133E operator() (__closure=<optimized out>) (C:\...\thread test.cpp:17)
#5 00000000 0x00000000 in ??() (??:??)

Without optimizations, that becomes:

#0 00000000 0x6c1c1214 in ??() (??:??)
#1 00401348 operator() (__closure=0x898f90) (C:\...\thread test.cpp:17)
#2 00401780 boost::detail::thread_data<main()::<lambda()> >::run(void)(this=0x898f70) (c:/.../boost/thread/detail/thread.hpp:62)
#5 00000000 0x00000000 in ??() (??:??)

The first thing I tried was adding in the thr.detach(); line that I commented out above, but that produced the same result.

I’ve also tried the following to no avail:

  • Replacing the lambda with a function (I’m not sure how well Boost fits in with C++11 stuff) — crashes
  • Commenting out the FreeLibrary line — works fine, but I’d rather free it after loading it, even if it is reference-based. I’m also cautious about that kind of behaviour working later on.
  • Replacing the infinite loop in the DLL with one that returns — works fine, but I can’t count on that
  • Not using LoadLibrary or anything and inlining the infinite loop — works fine, but I need to use DLLs:

boost::thread thr = []{for (;;);};

The DLL and cpp were both compiled on Windows 7 64-bit using GCC 4.7.1 with 32-bit output types. My version of Boost is 1.49.0. If memory serves, I think I got one or two tests in on Windows XP 32-bit (same compiler etc) before moving to a different computer as well.

Why is this crashing? How can I ensure a function I call dynamically doesn’t hang my program?

  • 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-11T11:22:04+00:00Added an answer on June 11, 2026 at 11:22 am

    Fundamentally, you can’t do that. Threads don’t provide that kind of isolation. Use processes if you need that.

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

Sidebar

Related Questions

I understand the concept but i don't know why i require to use non-type
I'm trying to use require_once to call Mail.php but when I create a new
I use eclipse to develop an app engine project on maven that require war
I'm trying to create a sql statement but I require the use of a
I currently use Authlogic in a web-app to handle user authentication, but have now
My App will require the use of about 500 images and this number could
If I have a class hierarchy in which subclasses require use of more specific
I'm working on a couple apps which require the use of OpenGLes 2.0. I
I'm building an app that require to use Amazon web services. I've uploaded images
I have a console application that require to use some code that need administrator

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.