Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Multiple threads writing to stdout can cause encoding errors #500

Closed
Richard-Stump opened this issue Feb 2, 2023 · 1 comment
Closed
Assignees
Labels
bug Something isn't working

Comments

@Richard-Stump
Copy link
Contributor

Richard-Stump commented Feb 2, 2023

Multiple threads writing to stdout can cause utf-8 encoding errors. This is likely due to stdout not being atomic, or maybe the design of our VFS. A closer look needs to be taken to determine the issue here.

Program to replicate bug:

#include <iostream>
#include "main.h"

using namespace pros;

void my_task(void* str) {
    pros::Vision vision(20);
    while (true) {
        std::cout << (char*)str << std::endl;
        std::cout << vision.get_object_count() << std::endl;
        pros::delay(20);
    }
}

void opcontrol() {
    {
        std::string s = "Hello world";
        pros::rtos::Task t(my_task, (void*)(s.c_str()));
    }
    while (true) {
        pros::Motor(11).move(pros::Controller(E_CONTROLLER_MASTER).get_analog(E_CONTROLLER_ANALOG_LEFT_Y));
        pros::Motor(1).move(-pros::Controller(E_CONTROLLER_MASTER).get_analog(E_CONTROLLER_ANALOG_RIGHT_Y));
        std::cout << ("Hello from opcontrol\n") << std::endl;
        pros::Task::delay(20);
    }
}

Image

@Richard-Stump Richard-Stump added the bug Something isn't working label Feb 2, 2023
@Richard-Stump Richard-Stump changed the title BUG: stdout is not atomic. Multiple threads sending data may crash it BUG: Multiple threads writing to stdout can cause encoding errors Feb 2, 2023
@ryan-doan ryan-doan self-assigned this Mar 21, 2023
@WillXuCodes
Copy link
Member

Should have been fixed in this PR above ^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants