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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:28:43+00:00 2026-05-23T08:28:43+00:00

Larry Osterman writes about a real error found in Microsoft’s code, the offending code

  • 0

Larry Osterman writes about a real error found in Microsoft’s code, the offending code is

static DWORD WINAPI _PlayBeep(__in void* pv)
{
    UNREFERENCED_PARAMETER(pv);
    PlaySound(L".Default"NULL, SND_SYNC | SND_ALIAS);
    return 0;
}

LRESULT WndProc(...)
{
    :
    :
    case WM_KEYDOWN:
        if (!_AcceptInputKeys(wParam, lParam))
        {
            QueueUserWorkItem(_PlayBeep, NULL, 0);
        }
        break;
}

and Larry asks:

Given the simplicity of the code
above, to get the answer right, it’s
not enough to say what’s wrong with
the code (the problem should be
blindingly obvious). You also need to
be able to explain why this is so bad
(in other words, what breaks when you
do this).

The best answer is terse in the comments is not enough,

David’s VERY close to what’s going
wrong – now think about the context of
the application.

Can someone please explain fully what’s happening when this code runs?

  • 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-23T08:28:44+00:00Added an answer on May 23, 2026 at 8:28 am

    Read the answer page, it’s got a very detailed explanation

    http://blogs.msdn.com/b/larryosterman/archive/2009/06/29/what-s-wrong-with-this-code-part-26-the-answer.aspx

    Basically, don’t use QueueUserWorkItem for long-running work items because this can cause thread exhaustion in your process, or even deadlock in a very hard to debug way if you wait for work items to complete on a (necessarily) finite-sized thread pool. Same goes for the .Net equivalent of this API ThreadPool.QueueUserWorkItem btw.

    In this specific case, the workitem trigger (“press the down key”) and the resulting thread workitem (“sound a sync beep”) are very unbalanced, so that if user holds down or repeatedly hits his/her down key, the process will quickly hit fatal issues.

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

Sidebar

Related Questions

I was reading Larry Osterman's latest blog post about debugging a flickering problem in
hI, I'm trying to get this code from Larry Nyhoff's book to compile in
Can someone please xplain this code. Im reading larry ullmans book on php and
I'm quite new to php and have been reading Larry Ullman book to develop
I have this code in my cfm, which works <cfif not StructIsEmpty(form)> <cfset larray
I wonder what language Larry Page and Sergey Brin wrote Google with? I'm not
Quick question. Here is my code: #routes map.resources :customers, :has_many => [:addresses, :matchings] map.connect
I have some code that sorts table columns by object properties. It occurred to
NAMES = ['Alice', 'Bob','Cathy','Dan','Ed','Frank', 'Gary','Helen','Irene','Jack', 'Kelly','Larry'] AGES = [20,21,18,18,19,20,20,19,19,19,22,19] def nameage(a,b): nameagelist = [x
I wrote some mail merge code the other day and although it works I'm

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.