This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCSv5 Strange behavior with while()

Other Parts Discussed in Thread: TMS570LS3137

I have a while loop as follows:

notready=1;

while( notready );

notready gets modified by another thread. When debugging, the program stops at the while line and will never move on, even when notready gets changed to 0. (I can see the 0 value in the watch window). However, if I change it to the following:

while( notready==1 );

it works like a charm!

Any explanation from the CCS gurus?

  • This sounds like a case where the "volatile" keyword may be required.
    Please see this related thread for a similar situation: http://e2e.ti.com/support/development_tools/compiler/f/343/p/3415/173574.aspx#173574

  • Cam,

    Did you look at the generated assembly code in the disassembly window?

    It will depend on the type of notready, volatile?, the device/compiler you are using and the optimization level.

    If you looked at disassembly and it is not appearant, I suggest you copy and post the disassembly for the compiler/assemlby gurus to look at. 

    The following is the output from a TMS570LS3137 using optimization level 2, though slighty different it does not explain the behavior you are seeing.

              main:
    00003ad8:   E59FC020 LDR             R12, $C$CON1
    00003adc:   E3A00001 MOV             R0, #1
    00003ae0:   E58C0000 STR             R0, [R12]
    50         while (notready);
              $C$L1:
    00003ae4:   E59C0000 LDR             R0, [R12]
              $C$DW$L$main$2$E:
    00003ae8:   E3500000 CMP             R0, #0
    00003aec:   1AFFFFFC BNE             $C$L1
    52         while (notready==1);
              $C$DW$L$main$3$E, $C$L2:
    00003af0:   E59C0000 LDR             R0, [R12]
              $C$DW$L$main$4$E:
    00003af4:   E3500001 CMP             R0, #1
    00003af8:   0AFFFFFC BEQ             $C$DW$L$main$3$E

  • Thanks for the responses. The "volatile" keyword was the ticket. I should have thought of that :)