mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-03-10 07:18:46 -05:00
ConcurrentJobManager uses ThreadPool to do parallel Gdal RasterIO calls. Some tile gets corrupted...
This commit is contained in:
@@ -65,7 +65,6 @@ namespace openspace {
|
||||
class ConcurrentJobManager{
|
||||
public:
|
||||
ConcurrentJobManager()
|
||||
: _hasWorkingThread(false)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -76,17 +75,14 @@ namespace openspace {
|
||||
|
||||
|
||||
void enqueueJob(std::shared_ptr<Job<P>> job) {
|
||||
_incomingJobs.push(job);
|
||||
if (!_hasWorkingThread) {
|
||||
_hasWorkingThread = true; // Can only be set to true by the main thread
|
||||
executeJobsInSeparateThread();
|
||||
}
|
||||
TileProvider::threadPool.enqueue([this, job]() {
|
||||
job->execute();
|
||||
_finishedJobs.push(job);
|
||||
});
|
||||
}
|
||||
|
||||
void clearEnqueuedJobs() {
|
||||
while (_incomingJobs.size()) {
|
||||
_incomingJobs.pop();
|
||||
}
|
||||
TileProvider::threadPool.clearTasks();
|
||||
}
|
||||
|
||||
std::shared_ptr<Job<P>> popFinishedJob() {
|
||||
@@ -102,33 +98,8 @@ namespace openspace {
|
||||
|
||||
private:
|
||||
|
||||
|
||||
void executeJobsInSeparateThread() {
|
||||
// Create new thread and run workerThreadMainTask on that thread
|
||||
std::thread t(&ConcurrentJobManager::workerThreadMainTask, this);
|
||||
t.detach();
|
||||
}
|
||||
|
||||
void workerThreadMainTask() {
|
||||
while (_incomingJobs.size() > 0) {
|
||||
auto job = _incomingJobs.pop();
|
||||
|
||||
job->execute();
|
||||
|
||||
_finishedJobs.push(job);
|
||||
}
|
||||
|
||||
_hasWorkingThread = false; // Can only be set to false by worker thread
|
||||
}
|
||||
|
||||
ConcurrentQueue<std::shared_ptr<Job<P>>> _incomingJobs;
|
||||
ConcurrentQueue<std::shared_ptr<Job<P>>> _finishedJobs;
|
||||
|
||||
// Using this atomic bool is probably not optimal - Should probably
|
||||
// use a conditional variable instead
|
||||
std::atomic<bool> _hasWorkingThread;
|
||||
std::atomic<int> _numActiveThreads;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -113,8 +113,15 @@ namespace openspace {
|
||||
} // release lock
|
||||
|
||||
// wake up one thread
|
||||
std::cout << "Notify one thread" << std::endl;
|
||||
condition.notify_one();
|
||||
}
|
||||
|
||||
void ThreadPool::clearTasks() {
|
||||
{ // acquire lock
|
||||
std::unique_lock<std::mutex> lock(queue_mutex);
|
||||
tasks.clear();
|
||||
} // release lock
|
||||
}
|
||||
|
||||
|
||||
} // namespace openspace
|
||||
@@ -59,6 +59,7 @@ namespace openspace {
|
||||
~ThreadPool();
|
||||
|
||||
void enqueue(std::function<void()> f);
|
||||
void clearTasks();
|
||||
|
||||
private:
|
||||
friend class Worker;
|
||||
|
||||
@@ -45,6 +45,7 @@ namespace openspace {
|
||||
|
||||
bool TileProvider::hasInitializedGDAL = false;
|
||||
|
||||
ThreadPool TileProvider::threadPool(10);
|
||||
|
||||
|
||||
TileProvider::TileProvider(
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace openspace {
|
||||
|
||||
void prerender();
|
||||
|
||||
|
||||
static ThreadPool threadPool;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user