Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CSingleLock doubt

CSingleLock doubt

Scheduled Pinned Locked Moved C / C++ / MFC
questionlearning
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    ledallam
    wrote on last edited by
    #1

    Hi, I am working on Threading and am using CSingleLock to control access to shared resource. I have a doubt..must the CCritical section be member of the class or can it be local to the function? 1) void foo() { CCriticalSection CritSection; CSingleLock singleLock(&CritSection); } void foo1() { CCriticalSection CritSection; CSingleLock singleLock(&CritSection); } 2) CCriticalSection m_CritSection; void foo() { CSingleLock singleLock(&m_CritSection); }void foo1() { CSingleLock singleLock(&m_CritSection); } Are both the baove approaches correct? Please give me your inputs on this? Thanks

    K R 2 Replies Last reply
    0
    • L ledallam

      Hi, I am working on Threading and am using CSingleLock to control access to shared resource. I have a doubt..must the CCritical section be member of the class or can it be local to the function? 1) void foo() { CCriticalSection CritSection; CSingleLock singleLock(&CritSection); } void foo1() { CCriticalSection CritSection; CSingleLock singleLock(&CritSection); } 2) CCriticalSection m_CritSection; void foo() { CSingleLock singleLock(&m_CritSection); }void foo1() { CSingleLock singleLock(&m_CritSection); } Are both the baove approaches correct? Please give me your inputs on this? Thanks

      K Offline
      K Offline
      kakan
      wrote on last edited by
      #2

      AFAIK, example 2 is correct.

      1 Reply Last reply
      0
      • L ledallam

        Hi, I am working on Threading and am using CSingleLock to control access to shared resource. I have a doubt..must the CCritical section be member of the class or can it be local to the function? 1) void foo() { CCriticalSection CritSection; CSingleLock singleLock(&CritSection); } void foo1() { CCriticalSection CritSection; CSingleLock singleLock(&CritSection); } 2) CCriticalSection m_CritSection; void foo() { CSingleLock singleLock(&m_CritSection); }void foo1() { CSingleLock singleLock(&m_CritSection); } Are both the baove approaches correct? Please give me your inputs on this? Thanks

        R Offline
        R Offline
        Ryan Binns
        wrote on last edited by
        #3

        The CCriticalSection object must be a member of the class. Both locks must operate on the same object.

        Ryan

        "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups