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. Interview Test Question

Interview Test Question

Scheduled Pinned Locked Moved C / C++ / MFC
questioncareer
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.
  • Richard Andrew x64R Offline
    Richard Andrew x64R Offline
    Richard Andrew x64
    wrote on last edited by
    #1

    I was asked, "If we have mutexes, why do we need critical sections?" My answer was that mutexes protect resources and critical sections protect code. Was I on the right track?

    The difficult we do right away... ...the impossible takes slightly longer.

    D A 2 Replies Last reply
    0
    • Richard Andrew x64R Richard Andrew x64

      I was asked, "If we have mutexes, why do we need critical sections?" My answer was that mutexes protect resources and critical sections protect code. Was I on the right track?

      The difficult we do right away... ...the impossible takes slightly longer.

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Richard Andrew x64 wrote:

      Was I on the right track?

      You decide: Critical Section vs. Mutex - MSDN Blogs[^]

      "One man's wage rise is another man's price increase." - Harold Wilson

      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

      "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

      1 Reply Last reply
      0
      • Richard Andrew x64R Richard Andrew x64

        I was asked, "If we have mutexes, why do we need critical sections?" My answer was that mutexes protect resources and critical sections protect code. Was I on the right track?

        The difficult we do right away... ...the impossible takes slightly longer.

        A Offline
        A Offline
        Albert Holguin
        wrote on last edited by
        #3

        I would think that in general, mutexes are purely kernel controlled objects whereas critical sections are mostly "user mode primitives", meaning it's application level logic most of the time (which runs a lot faster without requiring the kernel to be involved). Of course, this also implies a critical section is bound within a process and cannot be shared across processes. The exception is when there actually is a conflict, then a critical section makes a kernel call for synchronization. If you write some test code, you should be able to notice the speed advantage of a critical section (and all the kernel system calls of a mutex).

        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