I am working with a multi-threaded physics library that uses callbacks during the physics update routine. GCSuspend() is called before the physics update, and GCResume() is called after.
The callbacks use the "c" calling convention. With a single core the program runs perfectly. A crash results when the physics use more than one thread. How can I make the callbacks thread-safe? As I understand it, all the function variables are "up for grabs" at any time. Each callback has a parameter indicating which thread is in use. So would I do something like this?:
Current code:
Thread-safe code:
The callbacks use the "c" calling convention. With a single core the program runs perfectly. A crash results when the physics use more than one thread. How can I make the callbacks thread-safe? As I understand it, all the function variables are "up for grabs" at any time. Each callback has a parameter indicating which thread is in use. So would I do something like this?:
Current code:
Function Callback( threadIndex:Int ) "C" Local a:Int a = 3 EndFunction
Thread-safe code:
Function Callback( threadIndex:Int ) "C" Local a:Int[ 2 ] a[ threadindex ] = 3 EndFunction