Re[2]: [Gc] Atomicity of GC_get_heap_size

Ivan Maidanski ivmai at mail.ru
Tue Nov 18 13:17:03 PST 2008


Hi!

"Boehm, Hans" <hans.boehm at hp.com> wrote:
> Good point.  They should acquire the GC lock.  We should conform to the C++0x rules whenever possible.   That means we should avoid data races whenever possible.

Here is the patch (trivial).

The rest of GC code already guards access to GC_heapsize, GC_large_free_bytes, GC_bytes_allocd, GC_bytes_allocd_before_gc with GC lock (except for GC_incr_bytes_allocd/freed() but the code (in "new_gc_alloc.h") using them is broken now anyway).

> 
> ....
> 
> Hans
> 
> > -----Original Message-----
> > From: gc-bounces at napali.hpl.hp.com
> > [mailto:gc-bounces at napali.hpl.hp.com] On Behalf Of Ivan Maidanski
> > Sent: Tuesday, November 18, 2008 4:29 AM
> > To: gc at napali.hpl.hp.com
> > Subject: [Gc] Atomicity of GC_get_heap_size
> >
> > Hi!
> >
> > Q: Should GC_get_heap_size(), GC_get_free_bytes(),
> > GC_get_bytes_since_gc() and GC_get_total_bytes() have some
> > sort of locking (at least, on targets where AO_t is not word)?
> >
> > Bye.

Bye.

-------------- next part --------------
diff -ru bdwgc/misc.c updated/bdwgc/misc.c
--- bdwgc/misc.c	2008-11-17 13:42:04.000000000 +0300
+++ updated/bdwgc/misc.c	2008-11-18 23:25:44.000000000 +0300
@@ -379,22 +379,42 @@
 
 GC_API size_t GC_CALL GC_get_heap_size(void)
 {
-    return GC_heapsize;
+    size_t value;
+    DCL_LOCK_STATE;
+    LOCK();
+    value = GC_heapsize;
+    UNLOCK();
+    return value;
 }
 
 GC_API size_t GC_CALL GC_get_free_bytes(void)
 {
-    return GC_large_free_bytes;
+    size_t value;
+    DCL_LOCK_STATE;
+    LOCK();
+    value = GC_large_free_bytes;
+    UNLOCK();
+    return value;
 }
 
 GC_API size_t GC_CALL GC_get_bytes_since_gc(void)
 {
-    return GC_bytes_allocd;
+    size_t value;
+    DCL_LOCK_STATE;
+    LOCK();
+    value = GC_bytes_allocd;
+    UNLOCK();
+    return value;
 }
 
 GC_API size_t GC_CALL GC_get_total_bytes(void)
 {
-    return GC_bytes_allocd+GC_bytes_allocd_before_gc;
+    size_t value;
+    DCL_LOCK_STATE;
+    LOCK();
+    value = GC_bytes_allocd+GC_bytes_allocd_before_gc;
+    UNLOCK();
+    return value;
 }
 
 GC_bool GC_is_initialized = FALSE;


More information about the Gc mailing list