last time we talked about debugging
threads with the parallel Stacks window
but debugging tasks can be just as hard
so learn how we can debug those using
the parallel Stacks window on this
episode of Visual Studio toolbox
[Music]
hello everyone and welcome to another
episode of Visual Studio toolbox I'm
your host Leslie Richardson and today
I'm excited because we are joined once
again by Mark and REM from the visual
studio debugging Diagnostics team and
last week or last time not even last
week we talked about how you can debug
your threads with the parallel Stacks
window and now we're going to talk about
how you can use the parallel Stacks
window to debug your tasks and if you
want to watch the threads video link is
below so welcome back Mark and rum
thank you
awesome so we are going to talk about
tasks today so what are some of the
unique
problems that users might face when
they're trying to diagnose issues with
tasks versus threads
I I mean I I think I start the idea that
kind of tasks the async await
programming is everywhere now and rather
than kind of
take on all the responsibility of
managing threats people simply use tasks
use the async async await keywords to
unlock the potential of parallel
programming and that's great
um but it's also there's some
interesting caveats to doing it well and
doing it incorrectly and again we think
parallel Stacks window is just like a
great opportunity for you to kind of
review how well you're doing it if
something's wrong maybe you can find it
using the parallel stacks
awesome so can we see how it works sure
thing let me show you an example
um this is my buggy demo code
application I have this is open source
app I have how it's a very reliable
application yeah right it's what I use
to quickly kind of put together demo
code of things to do badly so if you
come across this in the open source
world this is the wrong way to do it
um inevitably this is the bad way of
doing it right so I'm gonna go ahead and
I'm going to execute an endpoint on here
that I think is interesting now I
actually got the idea from this from a
fellow software engineer at Microsoft
called Sergey teplyakov and he was kind
of thinking about parallel Stacks window
and he was thinking about ways in which
tasks task-based programming can be done
incorrectly so I'm going to as I've done
before I'm going to pause uh the
debugger
um and it's gone into
the threads View and you can see there's
absolutely nothing wrong with this
threads view
um there's nothing kind of technically
wrong here so I'm going to go ahead and
switch to the task View
and while you know you're not seeing the
kind of
um
kind of danger signs danger danger
danger there is something I want to kind
of describe here maybe Ram can you help
me kind of describe this but there's
this kind of circular notion going on
here with these tasks that we think is
problematic and thankfully the parallel
Stacks window is kind of letting you
know
um that that that's an actual problem
set of links here unresponsive and I
clicked on my deadlock example here
and then then as I mentioned I post the
pause the application here and that has
never returned right so what I've got
into the situation here is that that
request that I clicked on has never
actually returned
yeah so right now here it's um like the
whole thing about async is that
um the physical call stack or the
threads view may not actually tell you
anything
uh because nothing actually may be
running right now on a thread right uh
sometimes the whole thing about
asynchronous programming is that things
may run in the future you know uh kind
of like a promise things will run
sometime later and not necessarily
happening right now on the physical
stack so that's where the parallel
Stacks with tasks is quite helpful
because it kind of shows what is the
async uh call Stacks that are right now
happening in your application
so
as a general principle when you're using
the async await
model of programming to write
asynchronous code it makes writing async
code really easy right it's like you're
just writing regular synchronous code so
the debugger is also trying to do the
same thing to make sure you're debugging
is as easy as debugging synchronous code
the only thing we have to do is switch
to the parallel Stacks with tasks View
uh so the now async Stacks can get a bit
tricky because uh async Stacks need not
necessarily just be linear stocks you
have things like tasks or when all or
task dot when any and uh which
essentially causes kind of branching in
the async stacks so that's why sometimes
async Stacks can look a bit strange you
can have things like cycles and uh in
this case
you again you have a cycle and that's
really going to deadlock your
application because if one task is
awaiting another task and another task
is awaiting the same one you know it's
not really going to proceed so uh the
async uh like the battle Stacks with
tasks you can help you figure out these
kinds of issues and if you uh double
click on you know one of those streams
it will take you to the line of code
that uh you know that caused the issue
all right
so in this case it looks like it does
actually take you to that line of code
that might be at the very least a point
of Interest since in this case
um it's not really telling you
specifically what is wrong aside from
you're kind of going into a circular
yeah so in this case T1 is Awakening T2
and if you were to switch to the other
one you'll see that T2 is awaiting T1 so
that's kind of like a classic uh it's
kind of like a deadlock uh in the sense
that both the tasks are awaiting each
other and neither can really complete
before the other one was done and so you
can have a deadlock yeah so you go no
you go no you go yeah
so yeah what was surprising to me is
that I didn't actually know until Ram
kind of was letting me know about I
didn't know actually this was a
possibility with task with with async
awake scenarios and
um what um sir guy had kind of was
telling everybody on Twitter that you
know we were really happy to see is that
not only is this scenario possible but
parallel Stacks can't find it even with
parallel tasks so even if you've had all
these years of experience with threads
you probably wouldn't find it unless
you're able to construct the the entire
kind of um the kind of Machinery behind
the task
um call itself and so we've done that
for you here so there's no need for you
to kind of put that together in some
kind of uh in some kind of a weird way
we if you go to the parallel Stacks
window you can kind of get the feedback
you need
awesome
so um
both of you also mentioned like the call
stack and like in the previous
um episode we talked about how you can
use the call stack alongside
the parallel Stacks window to get a
sense of what is being called and when
and stuff does the same apply in a tasks
context
yeah the theme does apply actually
because kind of keeping in line with the
idea that asynchronous programming or
asynchronous debugging is you know we
try to make it as easy as synchronous
debugging if you were to double click
any of the frames in the Bible stocks
with tasks View
we will switch you to seeing the async
stack for example if you look at the
debug location toolbar above uh where it
says thread it just says leasing call
stack and uh so and if you look at the
call stack window it will show you uh
what the current async call stack that
you have selected is and you can see
that it starts out with cycle detected
because that's what uh you know that's
what we are at and that can tell you uh
and in this way even the AC cost act
would behave like a regular cost like
you can click on
um individual frames you can view locals
and uh you know in the locals window and
all that good stuff and uh
filtering external code works the same
way
and essentially it kind of models the
regular debugging experience so you know
debugging async code shouldn't be hard
and that should help you write that
racing code
I like that it even tells you um that a
cycle was detected in the call stack
that's great yeah and anytime you have a
cycle that's there in your asyn code
that typically means that you know
you're stuck there's no way your app is
going to proceed
yep
well great
that is really exciting I mean I've I
mean being on the team at one point in
time it's been cool to see how the
parallel Stacks both for tasks and for
Threads uh has evolves in recent years
like it looks so much different from how
it used to be just even back in BS 2019
and that's really exciting yeah and we
encourage people to put their feedback
coming this has kind of been the
response of customers using this tool
talking about this tool in public and
we're listening and if you have more
features that you want to include in
there let us know my my Twitter handle
is there just reach out I'm happy to
kind of talk about it
awesome yeah I can't wait to see what's
next for the parallel Stacks window
yeah definitely have more coming yay the
casts and threads can be real
tricky so yeah looking forward to it
well Mark and ronkumar thank you so much
for being on the show
for both episodes
thank you
yeah and y'all if you want to learn more
definitely check out the links in the
show notes below go check out the other
video on Parallel stacks for Threads if
you haven't already and yeah as Mark
mentioned share your feedback go to the
developer community and share their what
you feel like could be improved in the
space or you could also ping uh mark on
Twitter he's got his Twitter handle and
you can let him know there
so thanks once again everybody and until
next time happy coding
[Music]
Wednesday, February 4, 2026
Debugging tasks with the Parallel Stacks window
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment