fix wrong static declaration in pqithreadstreamer.cc#296
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix wrong static declaration in pqithreadstreamer.cc
This branch fixed a critical bug in the pqithreadstreamer class related to how thread sleep and timeout periods were managed.
The Problem
In the original code, the variables recv_timeout and sleep_period inside the threadTick() function were declared as static:
This bug was introduced by me (jolavillette) in
commit 2e2bcb8
Author: jolavillette jolavillette@gmail.com
Date: Fri Jan 2 22:17:30 2026 +0100
use adaptive timeout and sleep in pqithreadstreamer
cpp
static uint32_t recv_timeout = mTimeout;
static uint32_t sleep_period = mSleepPeriod;
In C++, a static variable inside a function is shared across all instances of that class. Since pqithreadstreamer is instantiated for every single peer connection (e.g., if you have 50 friends online, you have 50 instances), they were all fighting over the same two variables.
This created several issues:
Incorrect adaptation: The adaptive logic (which reduces sleep when there is data and increases it when idle) couldn't work properly because it was being updated by multiple threads simultaneously without coordination.
The Fix
The branch removed the static keywords and used instance member variables (mTimeout and mSleepPeriod) instead.
Now, each peer connection has its own independent timing state. This ensures that: