purduesigbots / pros

Source code for PROS kernel: open source C/C++ development for the VEX V5 microcontroller
https://pros.cs.purdue.edu
Other
259 stars 76 forks source link

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

Closed Richard-Stump closed 4 months ago

Richard-Stump commented 1 year ago

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

WillXuCodes commented 4 months ago

Should have been fixed in this PR above ^