locked
what's actually CMEMTHREAD RRS feed

  • Question

  • https://www.sqlskills.com/help/waits/cmemthread/

    what's actually "TREAD-safe-memory-object" ?

    Tuesday, August 11, 2020 8:38 AM

All replies

  • Thread safe is a flag which is put on memory object saying this can be accessed by more than one thread at a time. I would suggest you read below blog for the explanation

    Why CMEMTHREAD Wait Type Occurs?

    Quoting

    MEMOBJ acts like a HEAP in SQL Server engine, so SQL Server calls CreateMemoryObject function instead of HeapCreate, which is managed by SQL Server Memory Manager. CMEMOBJ is responsible to handle any kind of activity in SQL Server such as AllocFreeReAllocSize and Validate. Remember that CMEMOBJ is also not thread safe, therefore only one thread can access it at same time, it is similar to HEAP_NO_SERIALIZE in Windows.

    CMEMTHREAD acts like a serializer around CMEMOBJ, the SQL Server creates a memory object with a thread safe flag and CreateMemoryObject will return a pointer to CMEMTHREAD instead of the CMEMOBJ. By overriding some underling Windows methods, SQL Server is able to share a memory object among any thread and make it thread safe object.


    Cheers,

    Shashank

    Please mark this reply as answer if it solved your issue or vote as helpful if it helped so that other forum members can benefit from it

    My TechNet Wiki Articles

    MVP

    Tuesday, August 11, 2020 11:45 AM
  • Hi sakurai_db,

    In addition, please refer to How It Works: CMemThread and Debugging Them and Dynamic Memory Object Scaling which might help.

    Best Regards,

    Amelia


    ""SQL Server related"" forum will be migrated to a new home on Microsoft Q&A SQL Server!
    We invite you to post new questions in the "SQL Server related" forum’s new home on Microsoft Q&A SQL Server !
    For more information, please refer to the sticky post.

    Wednesday, August 12, 2020 6:50 AM
  • Hi sakurai_db,

    Did the answers above help you?

    Please feel free to let us know if you have any other question.

    If you find any post in the thread is helpful, you could kindly mark it as answer. This would benefit the community, and encourage the community member to keep working on your issues.

    Best Regards,

    Amelia


    ""SQL Server related"" forum will be migrated to a new home on Microsoft Q&A SQL Server!
    We invite you to post new questions in the "SQL Server related" forum’s new home on Microsoft Q&A SQL Server !
    For more information, please refer to the sticky post.

    Friday, August 14, 2020 9:01 AM
  • Tuesday, August 25, 2020 9:54 AM
  • Hi,

    This wait type is when a thread is waiting for access to a critical section of code around a thread-safe memory object (called CMemThread objects internally) so it can allocate or deallocate memory.

    (Books Online description: “Occurs when a task is waiting on a thread-safe memory object. The wait time might increase when there is contention caused by multiple tasks trying to allocate memory from the same memory object.”)


    Many Thanks & Best Regards, Jackson Chen

    Wednesday, August 26, 2020 5:05 AM
  • any real example for the thread-safe object ?
    Friday, August 28, 2020 8:34 AM
  • Hi,

    Read this


    Many Thanks & Best Regards, Jackson Chen

    Friday, August 28, 2020 8:53 AM
  • Hi,

    Read this


    Many Thanks & Best Regards, Jackson Chen

    ????
    Friday, August 28, 2020 5:23 PM