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 6917621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:45:12+00:00 2026-05-27T09:45:12+00:00

http://en.wikipedia.org/wiki/Lamport%27s_bakery_algorithm I have some problems to understand this algorithm. What happens if the current

  • 0

http://en.wikipedia.org/wiki/Lamport%27s_bakery_algorithm

I have some problems to understand this algorithm. What happens if the current thread and the thread, I am looking at the moment in the for loop are the same?

Threads: 0, 1, 2

Thread 1 takes ticket 1. Thread 2 takes ticket 2. Thread 0 does nothing.

Array = i: 0, 1, 2

Round 1:

  • Thread 1 (j=0): Array[0] = 0. next.
  • Thread 2 (j=0): Array[0] = 0. next.

Round 2:

  • Thread 1 (j=1): Array[1] = 1. (1,1) > (1,1)
  • Thread 2 (j=1): Array[1] = 1. (1,1) > (2,2)

(1,1) > (1,1) wrong.
(1,1) > (2,2) wrong.

Both threads are waiting…

What’s wrong? Is this a deadlock?

  • 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-27T09:45:13+00:00Added an answer on May 27, 2026 at 9:45 am

    The while loop in the algorithm allows a thread to enter critical section when the inequality does not hold. It says: wait as long as the condition (Number[j] != 0) && ((Number[j], j) < (Number[i], i) is true.

    Since (1,1) is not greater than (1,1) the thread 1 can pass the loop and enter the critical section.

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

Sidebar

Related Questions

I was reading this: http://en.wikipedia.org/wiki/Thread_safety Is the following function thread-safe? void foo(int y){ int
From this Wikipedia article: http://en.wikipedia.org/wiki/Hamiltonian_path_problem A randomized algorithm for Hamiltonian path that is fast
// Refer: http://en.wikipedia.org/wiki/Decimal I have a snippet like this in my java source code,
I've been reading about thread-safe singleton patterns here: http://en.wikipedia.org/wiki/Singleton_pattern#C.2B.2B_.28using_pthreads.29 And it says at the
http://en.wikipedia.org/wiki/All_nearest_smaller_values . This is the site of the problem and here is my code,
Suppose I want to turn this : http://en.wikipedia.org/wiki/Anarchy into this : en.wikipedia.org or even
http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization Is this design pattern possible in Java? If so, how? If not, why
At this link http://en.wikipedia.org/wiki/Tracing_(software ) they point out differences between server logs and trace
This is from wikipedia: http://en.wikipedia.org/wiki/Arraylist under Performance . ArrayList: constant time for remove(), add()
[ is not classed a unicode character http://en.wikipedia.org/wiki/List_of_Unicode_characters (my guess) as to why this

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.