Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4541858
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T15:18:13+00:00 2026-05-21T15:18:13+00:00

For a uni-processor, the lock algorithm is pretty simple. Lock(threadID) { Disable Interrupts If

  • 0

For a uni-processor, the lock algorithm is pretty simple.

Lock(threadID) {
  Disable Interrupts
  If lock is already owned by same thread{
    Restore Interrupts
    return
  }
  if lock is free {
    make lock busy
    set current thread as the owner of the lock
  }
  else {
     add threadID to the lock queue.
  }
  Restore Interrupts
  return
}

But how do we implement this code in multiprocessor/multicore systems. What if 2 cores/procs try to give the same lock to different processes.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T15:18:14+00:00Added an answer on May 21, 2026 at 3:18 pm

    Mutexes are generally implemented with atomic operations on a single memory value. For instance, a lock can be a single word that is free when 0 and locked when 1. To acquire the lock, the processor will lock the memory bus (so no other processors can read or write to memory), read the most-current value of the word, set it to 1 if it is 0, and unlock the memory bus. To unlock, the word can be set to 0.

    That’s a simple example that doesn’t address what happens when the lock is contended. Different OSs handle that using different mechanisms. Linux uses something called futexes. I’m not sure what Windows or Macs do.

    Although the algorithm you posted is correct, non-kernel code can’t disable CPU interrupts, so user-space code will tend to use atomic operations even on a single core.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My professor in the uni has asked me to design a simple website with
I've not used Unit Tests before other than a quick introduction in a Uni
Overall Plan Get my class information to automatically optimize and select my uni class
Can two CPUs hold two different spin locks simultaneously at same time? So...does this
I am in the process of choosing project for uni. And I am really
I'd like to create a function that automatically generates uni and multivariate regression analyses,
I took my first 'fundamentals of programming' lab session at uni today. One thing
I'm about to create WPF application. So far at uni the only way we
Good Afternoon Gurus, I am pretty familiar with basic socket programming, and the IO::Socket
This is a complex question, please consider carefully before answering. Consider this situation. Two

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.