...
// in src\z\ZMemPool_Optimized.cpp
#ifdef __GCC__
if (__sync_bool_compare_and_swap(&MemTable[BitPosition],NewBlock,NewBlock->Next))
#else
if( (MemTable[BitPosition] == NewBlock) ? (MemTable[BitPosition]=NewBlock->Next),1:0)
#endif
which does the same job, but without lock.....
During development, we forgotten the atomic instructions here. It seemed to work. But when trying to track weird and inexplicable crash, we finally found it was this.
So, it won't work correctly without the atomic instruction at this particular place.
Because the comparison and the assignation are not atomic, something can happens between. The tread can be interrupted or another thread can execute the same code at the same time.
As unlikely it might sound statistically, it happens more often one could believe.
The weird about this kind of issue is that the occurrence may vary between machines from rare to frequent depending on a lot of parameters involving scheduler algorithm, number of cores.
Stabilizing the Blackvoxel core took a long time and involved many tests on a lot of machines, graphic cards (some remains to do...). Even with the powerful tools like valgrind we have on linux, some issues was long to track.
Sorry, should be Pointer not 32/64 bit switch...
needed to reverse b and c params and add test if result is the assigned value... not exactly the intrinsic.
#ifndef __GNUC__
# define __sync_bool_compare_and_swap(a,b,c) (InterlockedCompareExchangePointer((void*volatile*)a,c,b), (*a)==(c))
#endif
We suggest you to change the test on define because testing for gcc could trigger on some wrong case, as an example on a future MacOS port with LLVM toolchain.
So we recommend applying compiler/platform specific patch with testing for compiler and (when pertinent) to platform.
But our goal is primarily to support well Blackvoxel on one "official" compiler.
As we are only two in the team to do everything, we prefer to focus on doing one thing very well rather than several poorly.
The Blackvoxel Team