c++ 多线程, 一读一写, 为什么写线程 无法修改

#include
#include
#include

uint indx;
void wFunc();
void rFunc();

int main(){

    indx=0;

    std::thread *pwthd=new std::thread(wFunc);
    pwthd->detach();

    std::thread *prthd=new std::thread(rFunc);
    prthd->detach();

sleep(60);

}

void wFunc(){

    uint tmp=indx;

    while(true){
            tmp++;
            indx=tmp;
            std::cout<<"w indx:"<<tmp<<std::endl;
            sleep(1);
}

}

void rFunc(){

    uint tmp=indx;

    while(true){

            if(indx>tmp){
                tmp=indx;
                std::cout<<"r indx:"<<tmp<<std::endl;
            }

    }

}

加一个修饰

 volatile uint indx;

写线程 每秒 修改一次indx (indx=tmp;) 但是 读线程 判断indx 没有改动, 为什么 写线程修改不成功?