Quantcast
Channel: Forum - Recent Threads
Viewing all articles
Browse latest Browse all 5781

How to prevent GCC from optimizing out a busy wait loop?

$
0
0

With C/C++ optimization level = 01 or 02, this while loop code will not work.  It will become while (1);

timerdone = false;

led_timer0.p_api->start(led_timer0.p_ctrl);   // required because autostart = false.

while (1) {
   if (timerdone) {
      break;
   }
}

 

void led_timer0_callback(timer_callback_args_t * p_args)
{
   SSP_PARAMETER_NOT_USED(p_args);

   led_timer0.p_api->stop(led_timer0.p_ctrl);
   led_timer0.p_api->reset(led_timer0.p_ctrl);
   timerdone = true;
}

 

It will only work if I make optimization = 00

How can I make this while loop work with 02 optimization?

 

Thank you

Michael


Viewing all articles
Browse latest Browse all 5781

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>