Skip to content
This repository was archived by the owner on Feb 3, 2023. It is now read-only.

CrossplatformThread double delete#453

Merged
Octogonapus merged 1 commit into
OkapiLib:developfrom
theol0403:develop
Aug 13, 2020
Merged

CrossplatformThread double delete#453
Octogonapus merged 1 commit into
OkapiLib:developfrom
theol0403:develop

Conversation

@theol0403
Copy link
Copy Markdown
Member

@theol0403 theol0403 commented Aug 13, 2020

Description of the Change

When a task callback returns, it looks like RTOS deletes the task. Therefore, when a CrossplatformThread is destructed, and the task callback has already returned, it is deleting an already deleted task. This causes a segfault.

Motivation

Segfaults are bad, though I think this situation is fairly rare: a short-lived task being held by a CrossPlatformThread that will be destructed before program end.

Possible Drawbacks

It's possible that STATE_INVALID might also need to be checked on, but I don't think so.

Verification Process

This causes the unit tests in my own code to pass and not segfault. This is only reproducible on the V5 brain, std::threads behave better when double deleted (or they aren't deleted when the callback ends).

Otherwise my code works fine and CrossplatformThread still works.

Example

This segfaults:

void initialize() {
        CrossplatformThread c([](void*){std::cout << "i am a fickle task" << std::endl;}, nullptr);
        pros::delay(500);
}

@theol0403 theol0403 added the bug Something isn't working label Aug 13, 2020
Copy link
Copy Markdown
Member

@Octogonapus Octogonapus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Segfaults are bad

I won't argue against this one.

@Octogonapus Octogonapus merged commit 644b7f7 into OkapiLib:develop Aug 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants