My (C++) code runs a number of agents the reactions of which are scheduled and executed in a worker pool. The machine (having 4 dual-core CPUs) runs a total of 8 workers. Every time a reaction is triggered it is scheduled to run on a worker which can be any of the 8. I'm using (or better, want to use) LMDB's shared memory model to access and update data, which can happen in multiple reactions (tasks) of a single agent. LMDB's model is:
(1) opening an environment (once, at agent initialization);
(2) opening a database (hopefully as (1)...);
(3) opening a transaction (either per reaction or reused (?) over multiple reactions ...);
(4) access/update data in the database.
However, on and off I encounter opening problems related to (2), probably (... my guess ...) when two reactions are scheduled on workers on the same CPU (... different cores but same process ...?).
Question:
- Has anyone dealt with the problem before?
- I.o.w.: with a runtime where worker processes execute tasks, what is the correct approach for the tasks accessing shared memory?