Tabling concurrency: new posix functions

This may (or may not) be relevant since Jan is working on the concurrent implementation of tabling. Several new posix functions are now available in the newly released glibc 2.30

Add new POSIX-proposed pthread_cond_clockwait, pthread_mutex_clocklock, pthread_rwlock_clockrdlock, pthread_rwlock_clockwrlock and sem_clockwait functions. These behave similarly to their “timed” equivalents, but also accept a clockid_t parameter to determine which clock their timeout should be measured against. All functions allow waiting against CLOCK_MONOTONIC and CLOCK_REALTIME. The decision of which clock to be used is made at the time of the wait (unlike with pthread_condattr_setclock, which requires the clock choice at initialization time).

This is important to make stable systems, because CLOCK_REALTIME can go backwards or make strange jumps in some cases (it took erlang quite a while to solve this problem).

Thanks for the tips. Timed operations are not part of this work though. Most is about lock free handling, a little mutex handling and a condition variable. It is good to see a timed mutex wait though as that should allow us to make waiting for a mutex interruptable.

This is the best! :grin:

Right. Using the just-pushed git version you can do …

:- table concat/3 as shared.

… and you’ll get a different result. For a description:

?- help('tabling-shared').

‘as dynamic’ allows for incremental tabling, e.g. clauses can be modified with assert, retract and friends.

It is quite easy. A thread involved in shared tabling may be waiting for some answer table that is owned by some other thread. So, thread A may be waiting for thread B. If we can create a cycle of such dependencies we have a problem :frowning:

Sure. You can use any data structure. Tries have advantages and disadvantages. Among the advantages are the fact that they are quite good and finding term variants and search and adding is done in a single action, making it relatively cheap to insert an answer into a table and know whether it is new or not. In most tabling scenarios we have either nodes with a single child or nodes with many children. Note that answer tires do not contain entire terms, just the (possible) instantiation of the variables of the call variant.

Once completed, SWI-Prolog compiles the trie into a clause that enumerates the members very efficiently and whose life time is subject to clause garbage collection. The clause is significantly more compact and future versions will remove the actual trie as this is no longer needed.

All this is in the tabling literature, although there is quite a bit of reading to grasp all this and some of the papers describe outdated implementation techniques. I’m grateful to Theresa Swift and David S. Warren for their guidance.