Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit dca1963

Browse files
committed
core.memory add user notes
1 parent 1ac45d1 commit dca1963

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

src/core/memory.d

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,34 @@
77
* Using this module is not necessary in typical D code. It is mostly
88
* useful when doing low-level _memory management.
99
*
10+
* Notes_to_users:
11+
*
12+
$(OL
13+
$(LI The GC is a conservative mark-and-sweep collector. It only runs a
14+
collection cycle when an allocation is requested of it, never
15+
otherwise. Hence, if the program is not doing allocations,
16+
there will be no GC collection pauses. The pauses occur because
17+
all threads the GC knows about are halted so the threads' stacks
18+
and registers can be scanned for references to GC allocated data.
19+
)
20+
$(LI If there are threads that the GC does not know about, i.e. the threads
21+
were created by calling the operating system thread creation APIs
22+
directly, or the C runtime thread creation APIs directly, and those
23+
threads hold references to GC allocated data, then the GC will not detect
24+
those references and may free the data. This will cause memory corruption.
25+
There are several ways to resolve this issue:
26+
$(OL
27+
$(LI Do not hold references to GC allocated data in such threads.)
28+
$(LI Register/unregister such data with calls to $(LREF addRoot)/$(LREF removeRoot) and
29+
$(LREF addRange)/$(LREF removeRange).)
30+
$(LI Maintain another reference to that same data in another thread that the
31+
GC does know about.)
32+
$(LI Disable GC collection cycles while that thread is active with $(LREF disable)/$(LREF enable).)
33+
$(LI Register the thread with the GC using $(CXREF thread, thread_attachThis)/$(CXREF thread, thread_detachThis).)
34+
)
35+
)
36+
)
37+
*
1038
* Notes_to_implementors:
1139
* $(UL
1240
* $(LI On POSIX systems, the signals SIGUSR1 and SIGUSR2 are reserved
@@ -67,17 +95,12 @@
6795
* happens and there is insufficient _memory available.)
6896
* )
6997
*
70-
* Copyright: Copyright Sean Kelly 2005 - 2009.
98+
* Copyright: Copyright Sean Kelly 2005 - 2015.
7199
* License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
72100
* Authors: Sean Kelly, Alex Rønne Petersen
73101
* Source: $(DRUNTIMESRC core/_memory.d)
74102
*/
75103

76-
/* Copyright Sean Kelly 2005 - 2009.
77-
* Distributed under the Boost Software License, Version 1.0.
78-
* (See accompanying file LICENSE or copy at
79-
* http://www.boost.org/LICENSE_1_0.txt)
80-
*/
81104
module core.memory;
82105

83106

0 commit comments

Comments
 (0)