Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How are "nonblocking" data structures possible?

I'm having trouble understanding how any data structure can be "nonblocking".

Say you're making a "nonblocking" hashtable. At some point or another, your hashtable gets too full, so you have to re-hash into a larger table.

This implies you need to allocate memory, which is a global resource. So it seems that you must obtain some sort of lock to prevent global corruption of the heap... irrespective of possible problems with your data structure itself!
But then that means every other thread must block while you allocate your memory...

What am I missing here?
(How) can you allocate memory without blocking another thread which is doing the same?

like image 797
user541686 Avatar asked May 30 '12 07:05

user541686


People also ask

How do lock free data structures work?

A data structure provides lock-freedom if, at any time, at least one thread can proceed. All other threads may be starving. The difference to obstruction-freedom is that there is at least one non-starving thread even if no threads are suspended.

What is a non-blocking process?

In computer science, an algorithm is called non-blocking if failure or suspension of any thread cannot cause failure or suspension of another thread; for some operations, these algorithms provide a useful alternative to traditional blocking implementations.

What is non-blocking as used in memory management?

Non-blocking algorithms are shared-memory multiprocessor algorithms that can avoid race conditions and guarantee correctness without using mutual exclusion locks.

What is non-blocking architecture?

Generally, a non-blocking architecture is based on method calls that, while they may execute for a long time on the worker thread, do not block the calling thread. If the calling thread needs to acquire information about or from the task the worker thread is executing, it is up to the calling thread to do that.


1 Answers

Two examples for non blocking designs are optimistic design and Transactional Memory.

The idea of this is - in most of the cases, the blocking is redundant - since two OPs can concurrently occur without interrupting each other. However, sometimes when 2 OPs occur concurrently and the data becomes corrupted because of it - you can roll back to your previous state, and retry.

There might still be locks in these designs, but the time the data is locked is significantly shorter, and is limited only to the critical time where the affect of the OP is taking place.

like image 53
amit Avatar answered Nov 15 '22 09:11

amit