HazardPointer


Object Hierarchy:

Gee.HazardPointer Gee.HazardPointer Gee.HazardPointer

Description:


[ Compact ]
public class HazardPointer<G>

Hazard pointer is a method of protecting a pointer shared by many threads. If you want to use atomic pointer that may be freed you should use following code:

   string *shared_pointer = ...;
HazardPointer<string> hptr = HazardPointer.get_hazard_pointer (&shared_pointer);
// my_string contains value from shared_pinter. It is valid as long as hptr is alive.
unowned string my_string = ptr.get ();
// instead of delete
ptr.release ((ptr) => {string *sptr = ptr;string ref = (owned)sptr;});
});

In some cases you may use helper methods which might involve copying of object (and are unsafe for unowned objects):

   Gtk.Window *window = ...;
Gtk.Window? local_window = HazardPointer.get_pointer (&window);
HazardPointer.set_pointer (&window, ...)
local_window = HazardPointer.exchange_pointer (&window, null);
HazardPointer.compare_and_exchange (&window, null, local_window);

The class also provides helper methods if least significant bits are used for storing flags.

HazardPointers are not thread-safe (unless documentation states otherwise).


Namespace: Gee
Package: gee-0.8

Content:

Classes:

Enums:

Static methods:

Creation methods:

Methods: