If this is your first visit, be sure to check out the FAQ by clicking the link above. You have to register before you can post.

If you have recently signed up, please make sure you log in so that your activity is registered. This is required for automatic promotions to work and to ensure your account is not deleted during the registration process.

Because System.Threading and OmniThreadLibrary are Delphi-only libraries and MTProcs has also his own problems (FreePascal-only, inefficient lock-based work-stealing, etc.) and at least System.Threading from Delphi XE7 has also a bit more inefficient work-stealing implementation.

Features:

Low-level-based design with optional high-level-based constructs

Designed for fully-strict fork-join model in mind (because it's less error-prone to work with it than with terminally-strict fork-join for my taste), but it can be also abused for more flexible models, the only important thing is, that you're releasing the jobs again as soon as they are completed (the simplest weay would be by calling TPasMP.Reset per workload-frame), otherwise you'll have memory leaks, or just use the PasMPJobFlagReleaseOnFinish flag.

It can be used a job scheduler for multithreaded game engines and so on

Work-first lock-free work-stealing dynamic-sized Chase-Lev queue/deque (where only the resizing code part of it isn't lock-free, so that on the other hand it is garbage-collector-free)

You always seem to produce exactly what I need when I need it! I've been wanting to use OmniThreadLibrary for ages for lock free queue implementations but the lack of FPC support makes it useless to me.

BeRo you are an absolute genius! thank you so so *so* much for sharing your work - this and all your other high quality gifts - I will make good use of it and will contribute back to the community in kind.

that's awesome , every one who's looking for speed would definitely love this so much , my next wish is that fpc will generate better vectorized code in the future .
btw , you really amazed me on how you get all that incredible energy to write all those great stuff kudos

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?

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 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.

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.

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.