CPP STL queue multithreaded error message: dereferencable

as follows, the main thread calls push () , and the second thread front () reads the head of the queue, and the team is busy when it is empty. As a result, line 11 front () reported an error deque iterator not dereferencable . After taking a look at the implementation of STL deque, I feel that the two operations should not conflict.

-sharpinclude "stdafx.h"

using namespace std;

queue<int>Q;
bool going = true;

void thread1() {
    while (going || !Q.empty()) {
        while (!Q.empty()) {
            int x = Q.front(); Q.pop();
        }
    }
}

int main()
{
    thread th(thread1);
    for (int i = 1; i <= 10000; iPP)
        Q.push(i);
    going = false;
    th.join();
    return 0;
}
Dec.31,2021
The containers in

stl are not thread safe, so be careful to lock them when using them

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e934fe-4721a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e934fe-4721a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?