<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://debianws.lexgopc.com/wiki143/index.php?action=history&amp;feed=atom&amp;title=Hazard_pointer</id>
	<title>Hazard pointer - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://debianws.lexgopc.com/wiki143/index.php?action=history&amp;feed=atom&amp;title=Hazard_pointer"/>
	<link rel="alternate" type="text/html" href="http://debianws.lexgopc.com/wiki143/index.php?title=Hazard_pointer&amp;action=history"/>
	<updated>2026-10-26T19:22:48Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.1</generator>
	<entry>
		<id>http://debianws.lexgopc.com/wiki143/index.php?title=Hazard_pointer&amp;diff=2063289&amp;oldid=prev</id>
		<title>imported&gt;Oceanicscope2 at 03:04, 23 June 2025</title>
		<link rel="alternate" type="text/html" href="http://debianws.lexgopc.com/wiki143/index.php?title=Hazard_pointer&amp;diff=2063289&amp;oldid=prev"/>
		<updated>2025-06-23T03:04:37Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Previous revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 03:04, 23 June 2025&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l27&quot;&gt;Line 27:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 27:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;*[[Hazard (computer architecture)]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;*[[Hazard (computer architecture)]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;*[[Finalizer]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;*[[Finalizer]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;*[[C++26]] - Adds &amp;lt;code&amp;gt;&amp;amp;lt;hazard_pointer&amp;amp;gt;&amp;lt;/code&amp;gt; to [[C++ Standard Library]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==References==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==References==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>imported&gt;Oceanicscope2</name></author>
	</entry>
	<entry>
		<id>http://debianws.lexgopc.com/wiki143/index.php?title=Hazard_pointer&amp;diff=1505100&amp;oldid=prev</id>
		<title>imported&gt;Frap at 18:15, 31 October 2024</title>
		<link rel="alternate" type="text/html" href="http://debianws.lexgopc.com/wiki143/index.php?title=Hazard_pointer&amp;diff=1505100&amp;oldid=prev"/>
		<updated>2024-10-31T18:15:16Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Short description|Programming concept}}&lt;br /&gt;
{{too technical|date=January 2014}}&lt;br /&gt;
In a [[Thread (computer science)|multithreaded]] [[computer science|computing]] environment, &amp;#039;&amp;#039;&amp;#039;hazard pointers&amp;#039;&amp;#039;&amp;#039; are one approach to solving the problems posed by [[dynamic memory management]] of the nodes in a [[non-blocking algorithm|lock-free]] [[data structure]]. These problems generally arise only in environments that don&amp;#039;t have [[automatic garbage collection]].&amp;lt;ref name=&amp;quot;Williams12&amp;quot;&amp;gt;Anthony Williams. &amp;#039;&amp;#039;C++ Concurrency in Action: Practical Multithreading.&amp;#039;&amp;#039; Manning:Shelter Island, 2012. See particularly Chapter 7.2, &amp;quot;Examples of lock-free data structures&amp;quot;.&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Any lock-free data structure that uses the [[compare-and-swap]] primitive must deal with the [[ABA problem]]. For example, in a lock-free stack represented as an intrusively linked list, one thread may be attempting to pop an item from the front of the stack (A → B → C). It remembers the second-from-top value &amp;quot;B&amp;quot;, and then performs &amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot; inline&amp;gt;&lt;br /&gt;
compare_and_swap(target=&amp;amp;head, newvalue=B, expected=A)&amp;lt;/syntaxhighlight&amp;gt;. Unfortunately, in the middle of this operation, another thread may have done two pops and then pushed A back on top, resulting in the stack (A → C). The compare-and-swap succeeds in swapping `head` with `B`, and the result is that the stack now contains garbage (a pointer to the freed element &amp;quot;B&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
Furthermore, any lock-free algorithm containing code of the form&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
Node* currentNode = this-&amp;gt;head;  // assume the load from &amp;quot;this-&amp;gt;head&amp;quot; is atomic&lt;br /&gt;
Node* nextNode = currentNode-&amp;gt;next;  // assume this load is also atomic&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
suffers from another major problem, in the absence of automatic garbage collection. In between those two lines, it is possible that another thread may pop the node pointed to by &amp;lt;code&amp;gt;this-&amp;gt;head&amp;lt;/code&amp;gt; and deallocate it, meaning that the memory access through &amp;lt;code&amp;gt;currentNode&amp;lt;/code&amp;gt; on the second line reads deallocated memory (which may in fact already be in use by some other thread for a completely different purpose).&lt;br /&gt;
&lt;br /&gt;
Hazard pointers can be used to address both of these problems. In a hazard-pointer system, each [[thread (computer science)|thread]] keeps a [[List (computing)|list]] of hazard pointers indicating which nodes the thread is currently accessing. (In many systems this &amp;quot;list&amp;quot; may be probably limited to only one&amp;lt;ref name=&amp;quot;Williams12&amp;quot;/&amp;gt;&amp;lt;ref name=&amp;quot;Alexandrescu04&amp;quot;&amp;gt;{{Cite news| author=Andrei Alexandrescu and Maged Michael | title=Lock-Free Data Structures with Hazard Pointers  | url=http://www.drdobbs.com/lock-free-data-structures-with-hazard-po/184401890 | journal=Dr. Dobb&amp;#039;s | year=2004}} (C++ oriented article)&amp;lt;/ref&amp;gt; or two elements.) Nodes on the hazard pointer list must not be modified or deallocated by any other thread.&lt;br /&gt;
&lt;br /&gt;
{{quote|1=Each reader thread owns a single-writer/multi-reader shared pointer called &amp;quot;hazard pointer.&amp;quot; When a reader thread assigns the address of a map to its hazard pointer, it is basically announcing to other threads (writers), &amp;quot;I am reading this map. You can replace it if you want, but don&amp;#039;t change its contents and certainly keep your &amp;lt;code&amp;gt;delete&amp;lt;/code&amp;gt;ing hands off it.&amp;quot;|2=[[Andrei Alexandrescu]] and Maged Michael|3=Lock-Free Data Structures with Hazard Pointers&amp;lt;ref name=&amp;quot;Alexandrescu04&amp;quot;/&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
When a thread wishes to remove a node, it places it on a list of nodes &amp;quot;to be freed later&amp;quot;, but does not actually deallocate the node&amp;#039;s memory until no other thread&amp;#039;s hazard list contains the pointer. This manual garbage collection can be done by a dedicated garbage-collection thread (if the list &amp;quot;to be freed later&amp;quot; is shared by all the threads); alternatively, cleaning up the &amp;quot;to be freed&amp;quot; list can be done by each worker thread as part of an operation such as &amp;quot;pop&amp;quot; (in which case each worker thread can be responsible for its own &amp;quot;to be freed&amp;quot; list).&lt;br /&gt;
&lt;br /&gt;
In 2002, [[Maged Michael]] of [[IBM]] filed an application for a U.S. patent on the hazard pointer technique,&amp;lt;ref name=&amp;quot;USPTO&amp;quot;&amp;gt;{{patent|US|20040107227|application|Maged M. Michael, &amp;quot;Method for efficient implementation of dynamic lock-free data structures with safe memory reclamation.&amp;quot; Filed on 3 December 2002.}}&amp;lt;/ref&amp;gt; but the application was abandoned in 2010.&lt;br /&gt;
&lt;br /&gt;
Alternatives to hazard pointers include [[reference counting]].&amp;lt;ref name=&amp;quot;Williams12&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
*[[Concurrent data structure]]&lt;br /&gt;
*[[Hazard (computer architecture)]]&lt;br /&gt;
*[[Finalizer]]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
*{{cite journal | author=Maged Michael | title=Hazard Pointers: Safe Memory Reclamation for Lock-Free Objects | journal=IEEE Transactions on Parallel and Distributed Systems | volume=15 | issue=8 | year=2004 | pages=491–504 | url=http://www.research.ibm.com/people/m/michael/ieeetpds-2004.pdf | doi=10.1109/TPDS.2004.8| citeseerx=10.1.1.130.8984 | s2cid=8373852 | archive-url=https://web.archive.org/web/20171104135736/http://www.research.ibm.com/people/m/michael/ieeetpds-2004.pdf | archive-date=2017-11-04}}&lt;br /&gt;
&lt;br /&gt;
==External links==&lt;br /&gt;
*[http://amino-cbbs.sourceforge.net/ Concurrent Building Blocks] - C++ implementation of Hazard Pointer (called &amp;quot;SMR&amp;quot;) and other lock-free data structures. Also has Java interfaces.&lt;br /&gt;
*[http://concurrencykit.org/ Concurrency Kit] {{Webarchive|url=https://web.archive.org/web/20140601032152/http://concurrencykit.org/ |date=2014-06-01 }} - C implementation of Hazard Pointer and lock-free data structures&lt;br /&gt;
*[http://atomic-ptr-plus.sourceforge.net/ Atomic Ptr Plus] - C/C++ library that has a Hazard Pointer implementation&lt;br /&gt;
*[http://www.johantorp.com/ The parallelism shift and C++&amp;#039;s memory model] - Contains C++ implementation for Windows in appendices&lt;br /&gt;
*[http://libcds.sourceforge.net/ libcds] - C++ library of lock-free containers and Hazard Pointer implementation&lt;br /&gt;
&lt;br /&gt;
[[Category:Programming constructs]]&lt;/div&gt;</summary>
		<author><name>imported&gt;Frap</name></author>
	</entry>
</feed>