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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:37:03+00:00 2026-06-16T04:37:03+00:00

I need to have a function busy-wait. for(long int j=0; j<50000000; ++j) ; When

  • 0

I need to have a function busy-wait.

for(long int j=0; j<50000000; ++j)
  ;

When I compile in release mode, this gets optimized out. Other than compiling in debug mode, is there some way to cause this to not get optimized out? I don’t particularly care about the actual number of the loop, but it must be a noticeable busy-delay.

  • 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-16T04:37:05+00:00Added an answer on June 16, 2026 at 4:37 am

    I don’t know why you need to keep the CPU busy, but let’s assume that you really have a good reason, like making sure you keep the CPU busy so it doesn’t think about that breakup it went through last week and get all depressed but I digress…

    The problem you are seeing is that the compiler performs “dead code elimination”: it sees that the loop does nothing (i.e. has no side-effects) and so cuts it out. So you could make it have a side-effect.

    A simple solution would be this function:

    void busywait(long iterations)
    {
        for(volatile long i = 0; i != iterations; i++)
            ;
    }
    

    By marking i as volatile you are ensuring that the loop has side-effects, since stores to volatile objects (i.e. the incrementing we perform) are treated as having side-effects.

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

Sidebar

Related Questions

I am busy writing my own collection type and need to have a function
I have this function in my js file. I need to give time for
I have this code public function TalentBox(x:int, y:int, arg_color:int = 0xFFFFFF):void { this.graphics.beginFill(arg_color); this.graphics.lineStyle(1.0,
i need one more thing i have function show_image() { document.write(<img src=+this.link+ ,alt=+this.alt+ ,width=600,
I have function LoadTempMovieList(), and need to load movies from sessionStorage. But it seems
I have some function where I need to pass a point datatype . somefunc(United
I have a function that i need to call on iframe mousemove(). But i
I have need for a function pointer that takes two arguments and returns a
I have two function and I need to execut in one onClick . The
I have a function that takes an array of objects and I need 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.