NvSciError result = NvSciError_Success;
NvSciSyncFence sharedFence = NvSciSyncFenceInitializer;
// Always initialize with the Initializer
NvSciSyncFence localFence = NvSciSyncFenceInitializer;
// Generate a new fence for the signaler
result = NvSciSyncObjGenerateFence(syncObj, &localFence);
if (result != NvSciError_Success) {
goto fail;
}
// Duplicate fence before sharing
result = NvSciSyncFenceDup(&localFence, sharedFence);
if (result != NvSciError_Success) {
goto fail;
}
// Create more duplicates if necessary
// Communicate the fence to the waiter.
// ex. via NvSciIpc
// After sharing the fence with the waiter, the local copy is no longer necessary, so dispose of it
// This call cleans references to sync object and is needed for proper freeing
NvSciSyncFenceClear(&localFence);
// Do something else, like some CPU job
// ...
// Signal the sync object
result = NvSciSyncObjSignal(syncObj);
if (result != NvSciError_Success) {
goto fail;
}