• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

B&S Data => Lock-waiting giveup CPU

 
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

when a 2nd threads tries to lock an "previously locked" record, do you guys think it is bad that it tries several time to "lock & wait" or that's not entirely "giving up CPU" ?

Below is an example:



Thanks
Alex
 
Ranch Hand
Posts: 332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This situation occurs if all your threads are waiting only on one object - in your case it seems, that it is mutexRecords. Any thread, which unlocks any record causes all waiting threads to become alive (by using notifyAll()) and all threads must check status of record they are trying to lock. Other reason is spurious wake-up.

This approach should be OK, Andrew's book says, that per-record locking is probably not required.

Did you make this test with 2 threads only? Can you investigate reason why 2nd thread wakes up multiple times? I suggest to add thread name to any traces you make.
 
Alex Belisle Turcot
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I understand the reason for this behavior (and designed it like that exactly).

I'm just wondering if a thread going back to "alive" state, just to go back to "wait" would count as "CPU usage".

The trace I pasted above were done when generating 100 threads, randomly accessing all records (with correct lock/unlock). To me, this is normal behavior, but I would be interested to know rancher's opinion on it (CPU usage).

Thanks
Alex
[ November 11, 2007: Message edited by: Alex Belisle Turcot ]
 
Alex Belisle Turcot
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok well I found other topics discussing that...

and I changed my code to synchronise/wait per record. And then only use notify, and the threads are no longer awaken just to call wait again.

I feel better with this approach.

Thanks
Alex
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic