Giter Club home page Giter Club logo

asp-task4-concurrency's Introduction

Concurrent Programming

This week you will implement a simple locking construct by relying only on primitive atomic operations. You will also implement a scalable, thread-safe concurrent data-structure. This will be achieved by following two different paths:

  1. using locks
  2. using a lock-free algorithm.

Deliverables

  1. Implement the spinlock that is declared in cspinlock.h to generate a library called libcspinlock.so.
  2. Implement a lock-based hashmap datastructure that is declared in chashmap.h to generate a library called liblockhashmap.so.
  3. Implement a lock-free hashmap datastructure that is declared in chashmap.h to generate a library called liblockfreehashmap.so.

NB: For tasks 1 and 3, only atomic primitives (e.g., compare-and-swap, atomic fetch-and-increment, etc.) are allowed. No synchronization library can be used (on Rust you can use std::sync::atomic).

Tip for Rust

You allocate datastructures via Box and cast those to/from raw pointer when implementing the alloc/free functions required by the chashmap and cspinlock interface.

Test Setup

There are three tests that needs to be passed to complete this task successfully.

Mutual exclusion

test_mutual_exclusion.py expects libcspinlock.so and checks whether the implementation of cspinlock guarantees that no two critical sections can execute concurrently.

Lock-based Hashmap

test_lockhashmap.py expects liblockhashmap.so and checks for the following:

  1. the concurrent hashmap is implemented correctly
  2. the hashmap scales with increasing number of threads

Lock-free Hashmap

test_lockfreehashmap.py expects liblockfreehashmap.so and checks for the following:

  1. the concurrent hashmap is implemented correctly
  2. the hashmap scales with increasing number of threads in high contention workloads.

Hints

  • Both lock-based and lock-free hashmap tests rely on the hashmap-driver.c to execute a workload on the hashmap. You can check the usage of this code to test your own.
  • The hashmap does not need to check if an element is already in the hashmap before inserting
  • Inserts should be relatively fast (i.e. insert at the beginning of the bucket, not the end)

Going further

  1. If you want to further develop your concurrent programming skills you can check other synchronization techniques such as Read-Copy-Update (RCU) and figure out how can the hashmap use RCU.
  2. Another direction that is important for lock-free programming is memory reclamation. You can try to understand how to safely reclaim deleted nodes from the hashmap.

References:

  1. MCS locks and qspinlocks
  2. A Pragmatic Implementation of Non-Blocking Linked-Lists
  3. Introduction to RCU
  4. Reclaiming Memory for Lock-Free Data Structures: There has to be a Better Way

asp-task4-concurrency's People

Contributors

kesamanthachen avatar github-classroom[bot] avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.