NXC  Version 1.2.1 r5
 All Data Structures Files Functions Variables Groups Pages
The safecall keyword

An optional keyword that can be specified prior to the return type of a function is the safecall keyword.

If a function is marked as safecall then the compiler will synchronize the execution of this function across multiple threads by wrapping each call to the function in Acquire and Release calls. If a second thread tries to call a safecall function while another thread is executing it the second thread will have to wait until the function returns to the first thread.

The code example below shows how you can use the safecall keyword to make a function synchronize its execution when it is shared between multiple threads.

safecall void foo(unsigned int frequency)
{
PlayTone(frequency, SEC_1);
}
task task1()
{
while(true) {
foo(TONE_A4);
Yield();
}
}
task task2()
{
while(true) {
foo(TONE_A5);
Yield();
}
task main()
{
Precedes(task1, task2);
}