Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login


That does not compute.

devel / comp.lang.c++ / raii can be helpful...?

o raii can be helpful...?Chris M. Thomasson

raii can be helpful...?


  copy mid

  copy link   Newsgroups: comp.lang.c++
From: (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: raii can be helpful...?
Date: Sat, 2 Dec 2023 20:21:05 -0800
Organization: A noiseless patient Spider
Lines: 42
Message-ID: <ukgvni$2no16$>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 3 Dec 2023 04:21:06 -0000 (UTC)
Injection-Info:; posting-host="8868b8f4564f0e4e4a8d04bd2a9ce818";
logging-data="2875430"; mail-complaints-to=""; posting-account="U2FsdGVkX1+qLa5eoabpRRrwIM1NIUcPR4A46aL1RvI="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:Vrh0tBAhJxxsZy/OcJjIpRpT4is=
Content-Language: en-US
 by: Chris M. Thomasson - Sun, 3 Dec 2023 04:21 UTC

Just in case I need to do any locking in my new project... I remember
this older work... Take notice of the raii based locker object in:

locker is meant to be on a per-thread basis. The view into a threads
goal of atomic, deadlock free, wrt its locked objects... Is this crap
wrt trying to show how raii can help, wrt the locker object?

This code allows a thread to dynamically lock multiple addresses in a
totally atomic fashion, and free of deadlock. It is based on hashing
pointers into a table of locks. A thread can create a little array of
hashed pointers, sort them, remove duplicates, then take all of the
locks in the table. The sorting and uniqueness factor prevents deadlock.
// pseudo-code

mtx_table lock_table;

// some vars
int a = 3;
short b = 6;
double x = 1.234;

// a thread
{ locker locks(lock_table); // our hashed locks

// a, x, and b are all locked!
} _________________

Well, locks.lock() and locks.unlock() can be automated via raii here...
locker is nice...

devel / comp.lang.c++ / raii can be helpful...?


rocksolid light 0.9.81
clearnet tor