Skip to content

Commit

Permalink
fix: ensure data mutex is unlocked a minimum amount of time
Browse files Browse the repository at this point in the history
fix occasional crash if the receive loop blocks the data mutex for most of the time. the gui loop nearly never gets its chance to block the mutex, especially on slower machines. this should be revesited to ensure no mutex related crashes can happen.
  • Loading branch information
vtx22 committed Mar 7, 2025
1 parent 27dbc27 commit 3f8275c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/DataHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void DataHandler::receiver_loop()
sparq_message_t message = receive_message();
if (message.valid)
{
std::lock_guard<std::mutex> lock(_data_mutex);
std::unique_lock<std::mutex> lock(_data_mutex);

if (message.message_type == sparq_message_type_t::STRING)
{
Expand All @@ -35,7 +35,11 @@ void DataHandler::receiver_loop()
{
add_to_datasets(message);
}

lock.unlock();
}

std::this_thread::sleep_for(500us);
}
}

Expand Down

0 comments on commit 3f8275c

Please sign in to comment.