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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:41:59+00:00 2026-05-22T02:41:59+00:00

Hey guys, I am reading these so called non-blocking techniques, but i have few

  • 0

Hey guys,
I am reading these so called non-blocking techniques, but i have few doubts :

1) lock-free operation are performed using atomic operation, now what are these atomic operation ? i mean at certain level they also need to have a lock right ? so Does this lock-free approach provides us locking at finer granularity only ?

2) they say non-blocking list, Now what a non-blocking list should be : if more than one threads comes at the same insertion, only one is going to get succeed, another one will do some other work right ?, but if other thread has no choice except inserting a node then how come it is non-blocking ? won’t it will get blocked until previous one is done ??

3) In java, how do they atomic operation ? doesn’t they do something like synchronized boolean .....
so how it is lock-free since they are acquiring lock i.e. synchronized section ?
4) CAS is usually used to implement atomic operation. So doesn’t cas allow only one operation to happen on the same object , and stops ( block ) others those want to operate on the same object ?
Sorry for so many doubts…
please clarify…

EDIT
what happens when i have a structure to update ? does it also supported by hardware ? No right, So doesn’t language would be acquiring locks at some level to make these structure operation atomic ?
About JAVA : there are AtomicReference and AtomicReferenceFieldUpdater class which provides updation to a object ( structure or any kind of object) , so can we compare them in terms of performance i mean speed ? Both in tern uses Unsafe class which uses Native class .

  • 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-22T02:42:00+00:00Added an answer on May 22, 2026 at 2:42 am

    Here is a simple lock free method in AtomicInteger

    public final int getAndIncrement() {
        for (;;) {
            int current = get();
            int next = current + 1;
            if (compareAndSet(current, next))
                return current;
        }
    }
    

    You can see that it gets the value, increments it and does a compareAndSwap. If the compareAndSwap doesn’t find the expect value, it means another thread has changed the value. So it tries again, and again, until all other threads trying to change the value have done so. This is lock free as no lock is used, but not blocking free as it may have to try again (which is rare) more than once (very rare)


    1) lock-free operation are performed using atomic operation, now what are these atomic operation ? i mean at certain level they also need to have a lock right ? so Does this lock-free approach provides us locking at finer granularity only ?

    However locks are implemented using more primitive operations. Otherwise you would need a lock to implement a lock adnauseum. The lock free approach uses atomic operations which avoid a full blown lock.

    2) they say non-blocking list, Now what a non-blocking list should be : if more than one threads comes at the same insertion, only one is going to get succeed, another one will do some other work right ?,

    If its thread safe they should both succeed, one at a time.

    but if other thread has no choice except inserting a node then how come it is non-blocking ?

    The term is “concurrent”. It still has to wait for the other thread to finish, it uses a lock-free approach to do this.

    won’t it will get blocked until previous one is done ??

    yes.

    3) In java, how do they atomic operation ?

    There is a call native method which performs the atomic operations. You can see this by reading the code. 😉 From look at the native code generated, these native method are turned into machine code instructions for performance (rather than being a true method call)

    doesn’t they do something like synchronized boolean ….. so how it is lock-free since they are acquiring lock i.e. synchronized section ?

    No, if you read the code, you would see that it doesn’t.

    4) CAS is usually used to implement atomic operation. So doesn’t cas allow only one operation to happen on the same object ,

    No.

    and stops ( block ) others those want to operate on the same object ?

    No.

    Again, if you look at how it is used it may make more sense.

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

Sidebar

Related Questions

Hey guys, I have a little button functionality that is not erring, but also
Hey guys! Here is the deal... I have a ComboBox defined in my window.
Hey guys. I'm not much of a programmer, but still need to do some
Hey guys, I have a client who wants their front site to have a
Hey guys. I'm designing a site that uses the Icefaces framework. I've been reading
Hey guys, I just started learning C++ and I have this code that I
hey guys, i want to perform the following operation: b = 'random' c =
Hey guys! I have some problems reloading my tableView. I have subclasses my tableView,
Hey guys. I'm currently playing with YUV file. Do you have any suggestion on
Hey guys, how the heck do I go about doing this. I have an

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.