class Test {
struct hazard_pointer {
std::atomic<void*> hp;
std::atomic<std::thread::id> id;
};
hazard_pointer hazard_pointers[max_hazard_pointers];
std::atomic<void*>& get_hazard_pointer_for_current_thread(){
std::thread::id id = std::this_thread::get_id();
for( int i =0; i < max_hazard_pointers; i++){
if( hazard_pointers[i].id.load() == id){
hazard_pointers[i].id.store(id);
return hazard_pointers[i].hp;
}
}
}
};
The function get_hazard_pointer_for_current_thread
can be executed parallelly. Is there data race
? On my eye there is no data race
because of atomic operation, but I am not sure.
So, please make me sure or explain why there is ( are ) data race(s).
Aucun commentaire:
Enregistrer un commentaire