Question: I was simply wondering, how reliable would it be to return a XML file through a PHP file, since XML is cached, and I am trying to find a way to easily update the XML file without having to actually clear the cache, and I've came up with a little PHP file that will load the XML file.

What my question is, if you echo a XML file, it comes out as plain text, but if I send the header along with the echo/print\_r is it as reliable as if I was to just load the plain .XML file? Or will this cause problems in some browsers?

```
header("Content-type: text/xml");
print_r(file_get_contents("http://xxxx.com/myfile.xml"));

```

Answer: 
You will never get sane behavior from `wait` without a predicate. Also, why do you keep releasing the lock only to immediately lock it again?

This is what you ened to do:

```
void Consumer::dostuff()
{
    std::unique_lock<std::mutex> ulck(mtx);    //locks shared data
    int i = 0;
    while(1)
    {

        // Correctly decide when to wait and when to stop waiting
        while (testvec.empty() || (testvec.back() == i))
            cv.wait(ulck);

        i = testvec.back();
        cout<<"last value: "<<testvec.back()<<endl;
    }
}

```

Condition variables are stateless and have no way to know whether they should wait or when they should stop waiting as those are functions of the shared state. It's your responsibility to code that, using the mutex to protect the shared state.

Notice this code only calls `wait` if it has to wait. You can only tell if you need to wait by inspecting the shared state. And notice it continue to call `wait` while it has to wait. Again, you can only tell if you can stop waiting by inspecting the shared state. The shared state is your responsibility -- condition variables are stateless.
> 
> I have a consumer and two producers.
> 
> 
> 

Wrong. You have 2 producers and a sampler. Nothing is consuming.

What you probably want is this (after simplification):

```
#include<deque>
#include<thread>
#include<iostream>
#include<mutex>
#include<chrono>
#include <condition_variable>

using namespace std;

deque<double> testvec;
mutex mtx;
condition_variable cv;

auto producer = [](int i)
{
    while(1)
    {
        std::unique_lock<std::mutex> ulck(mtx);
        testvec.push_back(i);
        ulck.unlock();
        cv.notify_all();
        i++;
        std::this_thread::sleep_for (std::chrono::milliseconds(i));
    }
};

void consume()
{
    while(1)
    {
        std::unique_lock<std::mutex> ulck(mtx);    //locks shared data

        // wait until there is something to consume...
        cv.wait(ulck, [&]{return not testvec.empty(); });

        /// ... consume it...
        auto val = testvec.front();
        testvec.pop_front();

        /// ... now unlock and work with the consumed data while unlocked
        ulck.unlock();

        /// ... do work
        cout<<"last value: " << val <<endl;
    }
}

int main( int argc, char ** argv )
{
    std::thread t1(producer, 222);
    std::thread t2(producer, 888);
    std::thread t3(consume);

    t1.join();
    t2.join();
    t3.join();
}

```

example output:

```
last value: 222
last value: 888
last value: 223
last value: 224
last value: 225
last value: 889
last value: 226
...

```