Well, manipulating a terrain is only possible on the mainthread since Gamestudio doesn't impose any kind of locking mechanism on its objects. However, you can load your data and process it in a secondary thread and unlike HeelX stated this makes sense for cases where you want to load the data without blocking the main thread.
Now about synchronizing, this is done by using mutexes. A mutex (or mutual exclusion) is an object that allows only one thread to pass execution and let the other threads wait. What you want to achieve can be done by creating one mutex and one state variable. Whenever you want to read or write from/to the variable you first lock the mutex to ensure that only one thread can alter the state variable.
So, here is some pseudo code for your main thread:
void checkState()
{
lock_mutex(globalMutex); // Lock the mutex so that only we can read it
if(globalState == allowReading)
processLoadedData(); // If the other thread signaled that we can read the data, read it.
unlock_mutex(globalMutex); // Unlock the mutex so other threads can lock it.
}
And here is the one for your secondary thread:
void loadData()
{
lock_mutex(globalMutex); // Lock the mutex
globalState = waitForData; // Mark the state as "we are currently busy reading"
unlock_mutex(globalMutex); // And then unlock the mutex so that we don't block other threads
readDataFromDisk(); // Read the actual data from disk
// And now set the state to ready to read.
lock_mutex(globalMutex);
globalState = allowReading;
unlock_mutex(globalMutex);
}
So, now for the actual functions you need to call:
Mutexes:
HANDLE myMutex; // Handle to a mutex
myMutex = CreateMutex(NULL, FALSE, NULL); // Default security attributes, not initially locked, no name
CloseHandle(myMutex); // Destroys the mutex
WaitForSingleObject(myMutex, INFINITE); // Locks the mutex and waits infinite for it
ReleaseMutex(myMutex); // Unlocks the mutex
Threads:
HANDLE myThread; // Thread handle
myThread = CreateThread(NULL, 0, myFunction, NULL, 0, NULL); // Default security attributes, default stack size, myFunction should be the entry function, no parameter passed to the function, default flags and we aren't interested in the id of the thread (otherwise we had to pass a pointer to LPDWORD variable
DWORD myFunction(void *ignored)
{
// Do something in the secondary thread
return 0; // Signal succes. If your thread failed, return 1.
}
I can highly recommend you the MSDN pages for all of the above functions, they have all the details about possible parameters and links to related functions that might help you too. Last but not least, use the C FILE functions (fopen(), fread(), fclose()) to read your file as the Gamestudio file_ functions might not work in a secondary thread.