Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Rentrant lock question

Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know there are a lot of locking questions already but anyway:

In my database class, I have several resources, such as the list of records, the list of reserved records and the random access file used to access the database binary file.
At the moment I am controlling access to all of these using a single Reentrant lock. If I need access to any of these 3 resources, I use this one lock. I also have a single Condition that is used together with this lock. This simplifies the locking and makes it easier to track down deadlocking.

I just have one doubt:
Would it be better to have a Reentrant lock for each of the 3 resources, and lock on all 3? This would make it clear which resources are being locked. - My only doubt is that 3 nested locks might not be necessary and might be bad style..

Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ciaran,

IMO it's advisable to use separate locks for each resource. No sense in having a thread block on a lock if it's being locked for a resource it's not even interested in. This is not bad form. Hope this helps.
Thanks tiny ad, for helping me escape the terrible comfort of this chair.
the value of filler advertising in 2020
    Bookmark Topic Watch Topic
  • New Topic