On Thu, 2013-12-19 at 17:16 +0200, Tal Hadad wrote: http://www.valadoc.org/#!api=gobject-2.0/GLib.WeakRef > > This is a simple solution thanks to the good design of GObject. > > Tal > > That might not always work, unfortunatly, due to how structs are implemented[1]. Beside - they are implemented currently using global lock in GObject[2].
> From: [email protected] > > To: [email protected] > > Date: Thu, 19 Dec 2013 08:59:44 +0800 > > Subject: [Vala] "vala friendly" atomic pointer > > > > Dear all, > > > > I want to implement something like these: > > * x = AtomicPointer.@get (ref atomicRef) // reader > > > > * AtomicPointer.@set (ref atomicRef, newref) // writer > > > > * return AtomicPointer.@get (ref atomicRef) // reader > > > > but have the benefit of vala ref counting. > > > > The best I can think of is: > > > > * lock (atomicRef) { x = atomicRef; } > > > > * lock (atomicRef) { atomicRef = newref; } > > > > * lock (atomicRef) { return atomicRef; } > > > > But lock is too course. > > e.g., lock (atomicRef) {x = atomicRef;} will also lock > > out other readers, whereas AtomicPointer.get won't. > > > > I realise that the exclusive region is small. > > But if you have a lot of readers, the effect > > may be significant. > > > > Any suggestions? > > > > > > Nice day > > Nor Jaidi Tuah > > > > > The combination of lock free and reference pointers is 'hard' (as long as you don't have double word CAS operation which is not implemented on practically any hardware). The only way I know about is by HazardPointers. Gee 0.8 or newer have it's implementation of HazardPointers[3]. The basic usage is as follows: MyObject *object_ptr; MyObject *read_object = HazardPointer.get_pointer<MyObject> (&object_ptr); The drawback is that you need to ensure that all operations are in HazardPointer.Context. You want the context to live in thread as long as you know that operation is taking place. Upon destruction all pointers are freed (exact method is specified by policy). Regards [1] https://bugzilla.gnome.org/show_bug.cgi?id=703996 [2] https://bugzilla.gnome.org/show_bug.cgi?id=705728 [3] http://www.valadoc.org/#!api=gee-0.8/Gee.HazardPointer _______________________________________________ vala-list mailing list [email protected] https://mail.gnome.org/mailman/listinfo/vala-list
