0

I have a struct that contains two fields: the number of readers and the number of writers. When I use a write lock, I modify the writers value, and print both of them. When I use read lock, I would like to modify the number of readers and then print both values. Can I do something like that? Or is there another way to do it, such as some kind of a counter with a mutex?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
mm mm
  • 19
  • 2
  • What are you locking, the struct itself? Or something else? – Sergio Tulentsev Nov 18 '19 at 21:32
  • It's possible that we'd better understand your question if you include a [MRE]. It would make it easier for us to help you if you reproduce your situation on the [Rust Playground](https://play.rust-lang.org) if possible, otherwise in a brand new Cargo project, then [edit] your question to include the additional info. There are [Rust-specific MRE tips](//stackoverflow.com/tags/rust/info) you can use to reduce your original code for posting here. Thanks! – Shepmaster Nov 18 '19 at 21:37
  • Yes, I'm locking a struct. I know, but I want to check number of readers. I know, that read locks are used for reading values – mm mm Nov 18 '19 at 21:38

0 Answers0