Results 1 to 8 of 8

Thread: PasMP - a parallel-processing/multi-processing library for Object Pascal

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    PasMP updated: https://github.com/BeRo1985/pasmp

    New features:

    • Thread-safe single producer single consumer queue (untyped and typed, bounded-only, lock-free)
    • Thread-safe multiple producer multiple consumer stack (untyped and typed, bounded and unbounded, lock-free on x86-32/x86-64/ARM32, lock-based on another CPU targets)
    • Thread-safe multiple producer multiple consumer queue (untyped and typed, bounded and unbounded, lock-free on x86-32/x86-64/ARM32, lock-based on another CPU targets)
    • Thread-safe hash table (untyped and typed, hybrid-implementation of lock-free and fine-graded lock-based single-operation code parts)
    • Thread-safe dynamic-sized array (untyped and typed, fine-graded lock-based)
    • TPasMPMath class with class static useful (primary bit-twiddling) math function methods
    • TPasMPInterlocked class with class static atomic function methods
    • TPasMPMemoryBarrier class with class static memory barrier function methods
    • TPasMPMemory class with class static aligned memory allocation function methods
    • Synchronisation primitives:
      • TPasMPEvent
      • TPasMPSimpleEvent
      • TPasMPCriticalSection
      • TPasMPMutex
      • TPasMPConditionVariableLock
      • TPasMPConditionVariable
      • TPasMPSemaphore
      • TPasMPInvertedSemaphore
      • TPasMPMultipleReaderSingleWriterLock
      • TPasMPMultipleReaderSingleWriterSpinLock
      • TPasMPSlimReaderWriterLock
      • TPasMPSpinLock
      • TPasMPBarrier
    • and more...


    And now, I'll port the Vulkan headers to pascal.

  2. #2
    Cool! This is exactly what I lacked in FPC!
    Thank you for sharing this!
    Are there any tests for the library?
    Or how did you know that your lock-free collections implementation are really thread safe and correct?

  3. #3
    Quote Originally Posted by Mirage View Post
    Cool! This is exactly what I lacked in FPC!
    Thank you for sharing this!
    Are there any tests for the library?
    Or how did you know that your lock-free collections implementation are really thread safe and correct?
    For many reasons:

    • I'm using the SPSC bounded queue approach since many years in my audio software stuff for as sound ringbuffer between two on-different-CPU-cores-pinned threads without any issues. And the SPSC boundung queue is really simple, because only one thread can be a producer and only one another thread can be a consumer. And the C++ boost::lockfree ringbuffer class seems using the same (or a very similar) SPSC bounded queue approach like I myself. Only the critical part is that the memory barriers are set correctly on the correct code positions, especially on CPU targets with weak memory models (for example ARM, PowerPC, etc.). x86 CPUs have comparatively a strong memory model. For more about weak vs. strong memory models, see: http://preshing.com/20120930/weak-vs...memory-models/
    • The lock-free MPMC queue stuff is based on the http://people.csail.mit.edu/edya/pub...ue-journal.pdf paper, which contains a "Correctness proof" text section.
    • The lock-free MPMC stack stuff is is based on the idea behind the concept of the internal workings of the "Interlocked Singly Linked Lists" Windows API, just stripped by the Depth stuff, which (the core concept behind it) is also well tested at the Microsoft Windows Operating System.
    • The lock-free job work stealing is based on http://www.di.ens.fr/~zappa/readings/ppopp13.pdf, which contains also a "Correctness proof" text section.


    And you have to consider the problem with the CPU cache lines for to avoid the false-sharing performance-degrade issues (https://en.wikipedia.org/wiki/False_sharing). Therefore, PasMP is more optimized for performance than for the memory usage, because almost everything in PasMP is CPU cache line aligned, also every item in your TPasMPDynamicArray, TPasMPBoundedStack, TPasMPBoundedQueue, etc. And a CPU cache line is on the most current x86 CPUs 64 bytes long.
    Last edited by BeRo; 21-02-2016 at 10:23 PM.

  4. #4
    Thanks for the answer.
    My question was more about implementation rather than about algorithms.
    When working with multithreading it's very easy to make a mistake and very hard to find it. Even tests don't guarantee anything. But them increasing probability to find errors.
    I think I'll write some test for your library when I'll integrate it to my projects.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •