Cover fe ature 47 january 2012 Published by the ieee computer Society 0018-9162/12/$31. 00 2012 ieee


algo  updates all records from a  vector



Download 1,78 Mb.
Pdf ko'rish
bet26/32
Sana13.01.2022
Hajmi1,78 Mb.
#355100
1   ...   22   23   24   25   26   27   28   29   ...   32
Bog'liq
Software-for-infrastructure

algo

 updates all records from a 



vector

 that matches 

a predicate and returns a list of indices of the updated 

records: 



vector  algo(vector& vr, Predicate pred)  

   /

/ update vr[i] if pred(vr[i])

{

      vector indices; 

// updated records

      for (int i = 0; i

 

    if (pred(vr[i]))  {

           unique_lock lck(vr[i].mtx); 

// acquire mutex

          

// update vr[i]

          indices.push_back(i);

 // record the update

 

    }

      return indices;

}

Here, I assume concurrency, so that some form of 

mutual exclusion is necessary. The 

vector

 and 


unique_

lock

 come from the C++ 11 standard library



Record

 and 


Predicate

 are assumed to be defined by the application. 

Two resources are required here: the memory for elements 

of the 


vector

 of indices, and the 



mutex

 members (



mtx

). 


The lifetime of the 

unique_lock

 determines how long its 



mutex

 is held. Both 



vector

 and 


unique_lock

 hold onto 

their resource while it’s in scope and release it when that 

scope is exited. 

Note that there is no user code for handling error re-

turns from 



algo



vector

 and 

unique_lock

 release their 

resources even if an exit from their scope is done by a 

return or by throwing an exception. Explicit resource 

management in the presence of errors can be a major 

source of complexity—for example, nested conditions or 

nested exception handlers—and obscure errors. Here, the 

resource management is made part of the semantics of the 

types used (


Download 1,78 Mb.

Do'stlaringiz bilan baham:
1   ...   22   23   24   25   26   27   28   29   ...   32




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish