Skip to content

Commit 31183d7

Browse files
author
pavl-x86-machine
committed
ConcurrentNativeBinaryLoader: fixed support for multi-threaded applications
1 parent a886f35 commit 31183d7

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

snaploader/src/main/java/electrostatic4j/snaploader/ConcurrentNativeBinaryLoader.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023-2024, The Electrostatic-Sandbox Distributed Simulation Framework, jSnapLoader
2+
* Copyright (c) 2023-2025, The Electrostatic-Sandbox Distributed Simulation Framework, jSnapLoader
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -35,6 +35,7 @@
3535
import java.util.List;
3636
import java.util.concurrent.locks.ReentrantLock;
3737
import electrostatic4j.snaploader.platform.NativeDynamicLibrary;
38+
import electrostatic4j.snaploader.throwable.UnSupportedSystemError;
3839

3940
/**
4041
* A thread-safe implementation for the NativeBinaryLoader.
@@ -56,7 +57,31 @@ public class ConcurrentNativeBinaryLoader extends NativeBinaryLoader {
5657
public ConcurrentNativeBinaryLoader(final List<NativeDynamicLibrary> registeredLibraries, final LibraryInfo libraryInfo) {
5758
super(registeredLibraries, libraryInfo);
5859
}
59-
60+
61+
@Override
62+
public NativeBinaryLoader initPlatformLibrary() throws UnSupportedSystemError {
63+
try {
64+
/* CRITICAL SECTION STARTS */
65+
lock.lock();
66+
return super.initPlatformLibrary();
67+
} finally {
68+
lock.unlock();
69+
/* CRITICAL SECTION ENDS */
70+
}
71+
}
72+
73+
@Override
74+
public NativeBinaryLoader loadLibrary(LoadingCriterion criterion) throws Exception {
75+
try {
76+
/* CRITICAL SECTION STARTS */
77+
lock.lock();
78+
return super.loadLibrary(criterion);
79+
} finally {
80+
lock.unlock();
81+
/* CRITICAL SECTION ENDS */
82+
}
83+
}
84+
6085
@Override
6186
protected void cleanExtractBinary(NativeDynamicLibrary library) throws Exception {
6287
try {

0 commit comments

Comments
 (0)