MemoryManager::getGlobal() - multithreading bug

22 views
Skip to first unread message

Palo Marton

unread,
Jan 15, 2014, 10:52:56 AM1/15/14
to asmji...@googlegroups.com
This construct is not multithreading safe in VS2012:

MemoryManager* MemoryManager::getGlobal() ASMJIT_NOTHROW
{
  static VirtualMemoryManager memmgr;
  return &memmgr;
}

This initializes memmgr variable on first call to this function. In multithreaded application this may happen from multiple threads at once and cause crash (happens to me). Solution is to make the variable static field of a class.

Palo

Petr Kobalíček

unread,
Jan 24, 2014, 8:53:54 PM1/24/14
to asmjit-dev
Hi,

I would like to remove this global getter at all.

Another way to fix would be to create your own VirtualMemoryManager and to pass it to every assembler/compiler you create. This way you won't have to worry about multithreading, because you will create the memory manager before any non-main thread is created.

Cheers,
Petr

--
 
---
You received this message because you are subscribed to the Google Groups "asmjit-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to asmjit-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages