Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

May all your PUSHes be POPped.


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

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

1
raii can be helpful...?

<ukgvni$2no16$2@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2859&group=comp.lang.c%2B%2B#2859

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m.thomasson.1@gmail.com (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$2@dont-email.me>
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: dont-email.me; posting-host="8868b8f4564f0e4e4a8d04bd2a9ce818";
logging-data="2875430"; mail-complaints-to="abuse@eternal-september.org"; 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:

https://groups.google.com/g/comp.lang.c++/c/sV4WC_cBb9Q/m/SkSqpSxGCAAJ

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
locks.push(&a);
locks.push(&x);
locks.push(&b);

locks.lock();
// a, x, and b are all locked!
locks.unlock();
} _________________

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

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor