PDA

View Full Version : QReadWriteLock Question



qtYoda
4th April 2011, 20:49
I'm using Win32 at the moment.

Does the QReadWriteLock take up limited system resources (besides just the memory to hold the object), or can you use as many instances of these as you want (subject to same memory caveat)?

In other words, do you need to use these locks as sparingly as possible, or can you feel free to get more granular to limit blocks when writing?

Thanks

wysota
4th April 2011, 21:54
Until the lock becomes effective (that is until some thread actually "hangs" on the lock) it's just a memory structure. Later it depends on the implementation of locking mechanisms on a particular platform.

qtYoda
4th April 2011, 22:52
Until the lock becomes effective (that is until some thread actually "hangs" on the lock) it's just a memory structure. Later it depends on the implementation of locking mechanisms on a particular platform.

Is it also just a memory structure after unlock? The actual time of the lock won't be long and it'll tend to be infrequent. Although I'm thinking of using many read write locks, they won't be locked at the same time.

wysota
4th April 2011, 23:51
Is it also just a memory structure after unlock?
No, I don't think so. Once the semaphore is allocated it probably stays allocated until the object is destroyed. But you can verify that in the source code.

How many locks are we talking about? 1000? more?

qtYoda
5th April 2011, 00:00
No, I don't think so. Once the semaphore is allocated it probably stays allocated until the object is destroyed. But you can verify that in the source code.

How many locks are we talking about? 1000? more?
Probably around 5000, but how many would actually be utilized, or even allocated would depend on the session. Probably not often near than many.

As followup, I was going to put the lock around a collection at the hash bucket level, rather than lock the whole collection when adding or removing. So there would be 1 per bucket.

Should I (or is it possible) just to have a semaphore that holds the read/write locks. I doubt I'd run into many instances of a lot of simultaneous writes to the collection.

wysota
5th April 2011, 07:20
It's easiest to just try and see.

qtYoda
6th April 2011, 04:16
It's easiest to just try and see.
Yeah, I know. I've got to get my debugger situation squared away. Right now its incredibly limited.

Are there any white papers on setting up a good multithreaded debugging system with Qt Creator and VisualStudio 2010?

wysota
6th April 2011, 09:23
What's wrong with using gdb?

qtYoda
7th April 2011, 04:23
Well, I'm new to c++, visual studio, Qt, Qt creator and coding multi-threaded applications --- should I add GDB to that too? Is there any books/papers on how to setup gdb with Qt/VS2010 to debug?

wysota
7th April 2011, 11:03
You don't have to setup anything. Actually if you're using VS2010 and MSVC then you should use the native Visual Studio debugger. Just click on the "Debug"
button in the IDE to start debugging. You might want to set some breakpoints first.