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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:59:05+00:00 2026-05-31T18:59:05+00:00

I am writing some code to perform explicit linking to a DLL. This code

  • 0

I am writing some code to perform explicit linking to a DLL. This code is offered to my users as an alternative to implicit linking with a .lib file. At the moment my planned code looks like this:

void DisableModule(int Module)
{
    typedef void (*DisableModuleProc)(int);
    static DisableModuleProc proc = NULL;
    if (proc == NULL)
        proc = (DisableModuleProc)GetProcAddress(hModule, "DisableModule");
    proc(Module);
}

There are lots of functions of this form, and I have excised the error checking for the purpose of this question.

My problem concerns thread safety. This function could potentially be called simultaneously from multiple threads. Clearly there is a race on the static variable _DisableModule. My belief is that because _DisableModule will be aligned on machine word boundary (either 32 or 64 bit boundary depending on target), that no tearing can occur and so the race is benign. It’s possible that GetProcAddress will be called more times than necessary, but I do not believe that affects correctness of the program.

Is my analysis correct?

  • 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-31T18:59:07+00:00Added an answer on May 31, 2026 at 6:59 pm

    This code is perfectly safe on x86 and amd64.
    At worst GetProcAddress is called several times.

    On other architectures there may be problems with partial writes being interrupted. To circumvent this, you could use atomics (InterlockedComparExchange …), but this is superfluous here.

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

Sidebar

Related Questions

So I was writing some code today that basically looks like this: string returnString
I'm writing some code to perform some game theory simulations. My world has several
I am writing some Java code to read each line of a data file
I am writing some code to determine whether a network domain is registered. For
I am writing some code and trying to speed it up using SIMD intrinsics
I'm writing some code for a class constructor which loops through all the properties
I'm writing some code in python and I'm having trouble when trying to retrieve
I'm writing some code that id like to be able to work with any
I was writing some code, and I notice a pattern in the exception handling
I'm writing some code that handles logging xml data and I would like to

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.