Skip to content

Update Thread.md #1166

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

Merged
merged 4 commits into from
Nov 15, 2019
Merged

Update Thread.md #1166

merged 4 commits into from
Nov 15, 2019

Conversation

AnotherButler
Copy link
Contributor

Add helpful tip from discussion in another repository (internal ticket IOTDOCS-1220).

Add helpful tips from discussion in another repository (internal ticket IOTDOCS-1220).
@AnotherButler
Copy link
Contributor Author

@kjbracey-arm Could you please review this to make sure it's right?

Is this also where information about thread state (Ready, Blocked and so on) and info threads would go?

@@ -10,6 +10,8 @@ The Thread class allows defining, creating and controlling parallel tasks.

All the internal thread data structures are part of the C++ class, but by default, the thread stack is allocated on the heap. Memory is allocated at the run time during the call to `start` method. If you don't want to use dynamic memory, you can provide your own static memory using the constructor parameters.

The main thread stack size is specified as `rtos.main-thread-stack-size` in the configuration .json file. That defines the main thread for `mbed_rtos_start` in `mbed_rtos_rtx.c`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Correct, but I think this needs to be the third paragraph. The paragraphs above and below are talking about extra threads you create using the Thread API, but this paragraph is a side point about the memory for the starting main thread (which is not created using Thread).

Possibly it should be a "Note", like in the section above.

@kjbracey
Copy link
Contributor

kjbracey commented Nov 11, 2019

Is this also where information about thread state (Ready, Blocked and so on) and info threads would go?

It could go here, yes, I can't immediately think of anywhere better. They're both about debugging threads, so if we have a general "debugging tips" page they could go there, but could be notes here.

(The Thread API does have the get_state call, but it's really just a debugging API. I've never seen it used except during printing out the thread list during a crash dump).

Move content and format it as a note, as requested in comments.
Add a debugging tips section.
@@ -89,6 +89,12 @@ The Callback API provides a convenient way to pass arguments to spawned threads.

[![View code](https://www.mbed.com/embed/?url=https://os.mbed.com/teams/mbed_example/code/rtos_threading_with_callback/)](https://os.mbed.com/teams/mbed_example/code/rtos_threading_with_callback/file/5938bdb7b0bb/main.cpp)

## Debugging tips

When debugging Thread, check the full RTX state (ready, blocked and so on) for a deadlock (two things waiting for each other) or a missed signal leading to an event machine stall. You can confirm a deadlock if you see two threads in the "blocked" state waiting for a resource that the other is supposed to signal.
Copy link
Contributor

Choose a reason for hiding this comment

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

"debugging threads", I think is better. Otherwise it should be Thread.

"waiting for" -> "each waiting for"?


When debugging Thread, check the full RTX state (ready, blocked and so on) for a deadlock (two things waiting for each other) or a missed signal leading to an event machine stall. You can confirm a deadlock if you see two threads in the "blocked" state waiting for a resource that the other is supposed to signal.

To reduce deadlocks, proactively code in a safe way by maintaining a mental ordering of your mutexes and never claiming a high-level mutex while holding a low-level one.
Copy link
Contributor

Choose a reason for hiding this comment

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

"mental ordering" sounds weird. Maybe just "ordering"?

I guess the point is that the system doesn't enforce this, so there's no way to follow this rule apart from self-discipline. Feels like you needs some sort of adjective to suggest that, but can't think of anything better.

(For comparison, in Symbian, to help with this, every mutex had a program-specified level number, and debug builds would stop with a diagnostic if you ever claimed a high-level one while holding a low-level one. Although being a debug-build-only check was annoying - if someone broke the rule and never tried a debug build, then other people found out when they made a debug build to look at their stuff and found the system stopped with a mutex diagnostic in debug mode. Debug builds weren't tested in CI.)

Update phrasing, as requested in comments, for clarity.
@AnotherButler AnotherButler merged commit 94389ea into development Nov 15, 2019
@AnotherButler AnotherButler deleted the AnotherButler-patch-2 branch November 15, 2019 22:21
AnotherButler pushed a commit that referenced this pull request Nov 15, 2019
Add helpful tip from discussion in another repository (internal ticket IOTDOCS-1220) by applying changes from PR #1166
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants