flightaware / speedtables

Speed tables is a high-performance memory-resident database. The speed table compiler reads a table definition and generates a set of C access routines to create, manipulate and search tables containing millions of rows. Currently oriented towards Tcl.
https://flightaware.github.io/speedtables/
BSD 3-Clause "New" or "Revised" License
66 stars 16 forks source link

Only one C extension can use shared memory speedtables #27

Closed lehenbauer closed 12 years ago

lehenbauer commented 12 years ago

If a second speedtables C shared library attempts to create a shared memory speedtable, it will malfunction. The previously defined tables will return results from the most recently defined one.

Comments in ctables/shared/shared.c indicate that some static variables need to be shared between C extensions for this to work.

While the ultimate fix would be to take the C files that are #included in each C extension into its own shared library, this will be tricky and I anticipate compatibility problems between autoconf-generated stuff and different operating systems following this path.

A much easier alternative would be to use the associated data (Tcl_GetAssocData) facility of Tcl interpreters to create a small structure containing the previously static variables, have the first extension create it and further extensions get a pointer to it. This should fix the problem.

lehenbauer commented 12 years ago

This is an extra problem because stapi defines speedtables one-shared-library-per-table.

lehenbauer commented 12 years ago

Fixed by commit 026f3ca78c89cc9dd3f11b6d261c5ea1fb583e43

lehenbauer commented 12 years ago

Test environment wasn't working as expected. Problem is not fixed under at least some circumstances.

lehenbauer commented 12 years ago

Fixed by commit 6eb2e96aa47838505fd978dbd84f3afc22d362d5

There is a fundamental structural problem with multiple segments due to non-relative addressing necessitating inheriting the shared memory or attaching to the segments in the same order as the owner, but it seems to be working OK now.

There are also potential issues with cleanly detaching multiple segments but they can be worked on later.