JosEPh_II
TBS WarLord


JosEPh

It was similar but far less refined. So I'd want to rewrite that part anyway.@AIAndy:
IIRC you added the multi-threaded spawn option a year ago, but it was never turned on. That said, if it was done in the same way as the property solver threading was, then it would probably be a good idea to change it's memory allocation as well, as I suspect it would give the same crashes.
It was similar but far less refined. So I'd want to rewrite that part anyway.
Currently I consider using a thread cached memory pool that only allocates via a lock if it runs out of appropriate memory in its thread pool.
You can give STL objects an allocator (although having an allocator with a state is not covered by the standard iirc).Hard to do in much of the code due to widespread use of STL objects, and the fact that many of those STL objects flow across the API to the EXE with the potential for allocation and deallocation to occur on different sides of the boundary. Would work fine for highly self-contained code (where the STL objects never leave some fairly tight scope), but not going to be a general solution that would allow us to start multi-threading a wider variety of the codebase.
Hard to do in much of the code due to widespread use of STL objects, and the fact that many of those STL objects flow across the API to the EXE with the potential for allocation and deallocation to occur on different sides of the boundary. Would work fine for highly self-contained code (where the STL objects never leave some fairly tight scope), but not going to be a general solution that would allow us to start multi-threading a wider variety of the codebase.
The proxy library implements the following dynamic memory functions:
 Standard C run-time dynamic memory functions: malloc, calloc, realloc, free
 Global C++ operators new and delete.
 Microsoft* C run-time library function _msize
You can give STL objects an allocator (although having an allocator with a state is not covered by the standard iirc).
If we move onwards to a lot of multi-threading then a mutex for allocation/deallocation is good and you would still be able to use the thread cached memory for when only one thread would use a certain object.
Yes, but I don't think there is any way around those considerations anyway (as you need to be sure that they are not written while you read and similar stuff).Yeh, I realize that. That works for o jects whose lifetime and scope is controlled and you can be certain is only being manipulated by your code (which is obviously true of the property system), I just meant that when we come to multithread wider partsof the code, which tends to have a rather sprawling call tree, it will be harder to be sure we only deal with obects that meet that criteria.
Yes, but I don't think there is any way around those considerations anyway (as you need to be sure that they are not written while you read and similar stuff).
I have looked into the memory code a bit and it seems like only the debug version uses the memory manager in the exe, the final release version uses the normal new which should be resolved by the linker to calls into the C Runtime msvcr71.dll, which is the multi threaded version including a thread safe memory allocation.I was planning on rendezvousing any AI threads such that they are only doing work while the game main thread is held inside CvGame::update(), so you know that the only concurrency is between our own threads at that point. Every now and again they all rendezvous and pause and we give the main thread a timeslice to exit from CvGame::update(). Other threads never call into the DLL anyway.
I have looked into the memory code a bit and it seems like only the debug version uses the memory manager in the exe, the final release version uses the normal new which should be resolved by the linker to calls into the C Runtime msvcr71.dll, which is the multi threaded version including a thread safe memory allocation.
So I am not sure why we get problems.
We are using the same memory allocator, just not like in the debug build with calls to the interface of the EXE, but instead using calls to the runtime DLL directly.That sounds wrong. We are always allocating things like CvStrings and giving them to the EXE, which uses and then deletes them. If we are using a different memory manager than the EXE is, that normal behaviour (irrespective of threading) should be crashing us. Are you sure we aren't trapping 'new' back to the core allocator (in non-debug builds)?
We are using the same memory allocator, just not like in the debug build with calls to the interface of the EXE, but instead using calls to the runtime DLL directly.
Unlikely, why would they have placed the DLL with the multi-threaded runtime in the Civ directories and then link against a static one.Exactly - so if the EXE is using the single-theaded runtime, and we are using the multi-threaded one, that's different allocators (they **MAY** use the same heap structures and hence we get away with it if they are not used concurrently, but I'd not want to stake my life on that)
Unlikely, why would they have placed the DLL with the multi-threaded runtime in the Civ directories and then link against a static one.