Skip to content

Putting sleep_for in a loop with a printf not ending with \n will not execute that printf #214

Open
@lefebvresam

Description

@lefebvresam

Purpose is to write the time and overwrite it at the same line:

    while(1) {
        time_t seconds = time(NULL);
        char buffer[32];
        strftime(buffer, 32, "%I:%M:%S %p", localtime(&seconds));
        printf("%s             \r", buffer);
        int i = 1000000;
        while(i--); // keep busy (sleep gives programming issues and printf cannot flush)
        ThisThread::sleep_for(5000);
    }

But when the ThisThread::sleep_for(5000); is inserted, the printf will never be executed.
If you change \r to \n it works, but then you get a new line on each printf.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDis is broken

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions