Categories
Mastering Development

C++ / objective c thread call losing parameter

Our code has just started crashing due to a thread calling a memory alloc function and losing the pointer to the memory pool.

The pointer is initialised before the threads are started, but when the thread uses it to call the memory alloc code, it’s zero.

In out init code we have

poolptr = InitMemoryPool ()

This sets it to a non zero memory address

In our .mm code on the thread we have

unsigned byte * p=(unsigned byte * ) MyAlloc ( poolptr, amount )

When the code gets into the MyAlloc function, poolptr is 0

Do I need my poolptr pointer to be volatile ? Even so, it’s value is set up before the thread starts and never changes, so if the compiler is assuming it’s a const, why doesn’t it have it set correctly ?

Also, this has worked fine for years – and just started going wrong yesterday, simultaneously on two peoples machines.

Any ideas ?

Leave a Reply

Your email address will not be published. Required fields are marked *