Skip to content

Commit

Permalink
JobSystemThreadPool: work around deadlocks on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Jul 8, 2024
1 parent f7a69ad commit a713e41
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,26 @@ public JobSystemThreadPool(int maxJobs, int maxBarriers, int numThreads) {
setVirtualAddress(systemVa, true);
}
// *************************************************************************
// JobSystem methods

/**
* Unassign the assigned native object, assuming there is one. Free the
* native object if the current system owns it.
*/
@Override
public void close() {
if (ownsNativeObject()) {
long systemVa = va();
free(systemVa);
}

unassignNativeObject();
}
// *************************************************************************
// native private methods

native private static long createJobSystem(
int maxJobs, int maxBarriers, int numThreads);

native private static void free(long systemVa);
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,17 @@ JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_JobSystemThreadPool_
= new JobSystemThreadPool(maxJobs, maxBarriers, numThreads);
return reinterpret_cast<jlong> (pPool);
}

/*
* Class: com_github_stephengold_joltjni_JobSystemThreadPool
* Method: free
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_JobSystemThreadPool_free
(JNIEnv *, jclass, jlong systemVa) {
#ifndef WIN32
// Attempting to delete a JobSystemThreadPool on Windows causes deadlock!
const JobSystem * const pSystem = reinterpret_cast<JobSystem *> (systemVa);
delete pSystem;
#endif
}

0 comments on commit a713e41

Please sign in to comment.