lundi 5 septembre 2016

difference between standard's atomic bool and atomic flag

I wasn't aware of the std::atomic variables but was aware about the std::mutex (wierd right!) provided by the standard. However one thing caught my eye. There are two seemingly-same(to me) atomic types provided by the standard, listed below -

  1. std::atomic bool type - Listed here - http://ift.tt/1lXDALs

  2. std::atomic_flag type - http://ift.tt/1qjt9jR

Also it is mentioned with the example of std::atomic_flag type -

std::atomic_flag is an atomic boolean type. Unlike all specializations of std::atomic, it is guaranteed to be lock-free. Unlike std::atomic, std::atomic_flag does not provide load or store operations.

which I fail to understand. is std::atomic bool type not guranteed to be lock-free? then it's not atomic or what?

So what's the difference b/w two and when should I use which?

Aucun commentaire:

Enregistrer un commentaire