locked
dostacksnapshot RRS feed

  • Question

  • Is DoStackSnapshot thread-safe or is it better to do sampling from a single thread .

    Monday, October 8, 2012 5:43 AM

Answers

  • Hi Xpsuser,

    Welcome to the MSDN Forum.

    Before I answer this question, please take a look at this blog: http://blogs.msdn.com/b/ericlippert/archive/2009/10/19/what-is-this-thing-you-call-thread-safe.aspx 

    It explained thread-safe very well.

    Based on the MSDN documentation:http://msdn.microsoft.com/en-us/library/ms230574.aspx 

    When the profiler wants to walk the stack, it calls DoStackSnapshot. Before the CLR returns from that call, it calls yourStackSnapshotCallback several times, once for each managed frame (or run of unmanaged frames) on the stack. When unmanaged frames are encountered, you must walk them yourself.

    The order in which the stack is walked is the reverse of how the frames were pushed onto the stack: leaf (last-pushed) frame first, main (first-pushed) frame last.

    For more information about how to program the profiler to walk managed stacks, see Profiler Stack Walking in the .NET Framework 2.0: Basics and Beyond in the MSDN Library.

    A stack walk can be synchronous or asynchronous, as explained in the following sections.

    Yes, I think it is thread-safe.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, October 9, 2012 8:57 AM
    Moderator
  • Hi.

    It's always best to have a single sampling thread from which to call DoStackSnapshot.  The issue is not so much whether DSS itself is thread-safe, but the fact that you need to suspend the target thread before walking it, which is dangerous business.  If you have have two walker threads suspending two target thread simultaneously, you're increasing your chances for deadlock or general confusion.

    Thanks,
    Dave

    Thursday, October 11, 2012 11:53 PM

All replies

  • Hi Xpsuser,

    Welcome to the MSDN Forum.

    Before I answer this question, please take a look at this blog: http://blogs.msdn.com/b/ericlippert/archive/2009/10/19/what-is-this-thing-you-call-thread-safe.aspx 

    It explained thread-safe very well.

    Based on the MSDN documentation:http://msdn.microsoft.com/en-us/library/ms230574.aspx 

    When the profiler wants to walk the stack, it calls DoStackSnapshot. Before the CLR returns from that call, it calls yourStackSnapshotCallback several times, once for each managed frame (or run of unmanaged frames) on the stack. When unmanaged frames are encountered, you must walk them yourself.

    The order in which the stack is walked is the reverse of how the frames were pushed onto the stack: leaf (last-pushed) frame first, main (first-pushed) frame last.

    For more information about how to program the profiler to walk managed stacks, see Profiler Stack Walking in the .NET Framework 2.0: Basics and Beyond in the MSDN Library.

    A stack walk can be synchronous or asynchronous, as explained in the following sections.

    Yes, I think it is thread-safe.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, October 9, 2012 8:57 AM
    Moderator
  • Hi.

    It's always best to have a single sampling thread from which to call DoStackSnapshot.  The issue is not so much whether DSS itself is thread-safe, but the fact that you need to suspend the target thread before walking it, which is dangerous business.  If you have have two walker threads suspending two target thread simultaneously, you're increasing your chances for deadlock or general confusion.

    Thanks,
    Dave

    Thursday, October 11, 2012 11:53 PM