Repository navigation
refactor(samples): replace pthreads with std::thread in multithreaded sample #13733
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
Open
Subham (Subham-KRLX)
wants to merge
5
commits into
microsoft:main
Choose a base branch
from
Subham-KRLX:feature/cpp11-thread-sample
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8aeeb69
Update build.cmd
Subham-KRLX 6b7cebe
samples(Fib): remove build task, update README, remove preLaunchTask …
Subham-KRLX 86d415a
Merge branch 'microsoft:main' into main
Subham-KRLX 1a16061
Merge branch 'microsoft:main' into main
Subham-KRLX c4831a0
samples(Fib): complete std::thread migration and fix all review issues
Subham-KRLX File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,32 @@ | ||
| # Fib | ||
|
|
||
| This code sample is to show debugging. Update `launch.json` and `tasks.json` in the `.vscode` folder to use your setup to build and debug. | ||
| This code sample demonstrates multithreaded debugging with C++11. It spawns 10 named threads, each computing Fibonacci numbers, and is designed to show how VS Code with the C/C++ extension can display named threads in the Threads and Call Stack views. | ||
|
|
||
| ## Building | ||
|
|
||
| Use one of the commands below to build the sample. | ||
|
|
||
| ```bash | ||
| # Linux / macOS | ||
| g++ -g *.cpp -std=c++11 -o fib.out | ||
|
|
||
| # Windows (MinGW) | ||
| g++ -g *.cpp -std=c++11 -o fib.exe | ||
| ``` | ||
|
|
||
| On Windows you can also run the included `build.cmd` (it expects the path to a MinGW `bin` folder and an output name): | ||
|
|
||
| ```powershell | ||
| .\build.cmd <Path\To\MinGW\Bin> fib.exe | ||
| ``` | ||
|
|
||
| ## Debugging | ||
|
|
||
| Update `launch.json` in the `.vscode` folder to point to your debugger if needed (e.g. set `miDebuggerPath` on Windows). | ||
|
|
||
| Press **F5** to build and launch the debugger. The build task compiles the sample automatically before starting the debug session. | ||
|
|
||
| ## Notes | ||
|
|
||
| - Thread naming uses `pthread_setname_np` on macOS/Linux so threads appear by name in the debugger's Threads / Call Stack view. On Windows the names are visible via the thread IDs. | ||
| - No `-lpthread` flag is needed: the sample uses `std::thread` for threading and only calls the native thread-naming API for debugger visibility. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| SET PATH=%PATH%;%1 | ||
| g++ -g *.cpp -lpthread --std=c++11 -O0 -o %2 | ||
| @echo off | ||
| SET PATH=%PATH%;%1 | ||
| g++ -g *.cpp --std=c++11 -O0 -o %2 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| void * thread_proc(void* ctx); | ||
| void thread_proc(int tid); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.