Problem: When the ExecuteQueue Function get's called there's already two existing Packets in Queue and they get called correctly (printed to console). But even though the ExecuteQueue Function get's looped in another Thread the Main Thread is blocked (It never gets to QueuePacket).
I already browsed stackoverflow and most Issues were related to .join but this one probably isn't (removing the .join makes no difference).
Main.cpp
int main() {
// Start Client
boost::thread tClient(&Networking::Client::Initialize, Networking::Client()); // Still in Main-Thread???!?!?
Networking::Client::QueuePacket(Networking::Packet::Types::Disconnect);
// Start Modules
tClient.join();
return 0;
}
Client.cpp (Only the necessary Functions)
static bool QueuePacket(Packet p) { // Pushes existing Packet
return Globals::Queue.push(p);
}
void ExecuteQueue() {
while (Client::Active && Globals::NetworkConnectivity) {
if (Globals::Queue.empty()) { Sleep(500); continue; }
Packet p(Packet::Types::Invalid);
if (!Globals::Queue.pop(p)) continue; // Copies Packet into p on Success
if (p.Type == Packet::Types::Disconnect) { Client::Active = false; } // Disconnects Queue
if (p.Type == Packet::Types::Invalid) { } // Find some error handling here
ExecutePacket(p);
}
}