Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
/ druntime Public archive
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/gc/impl/conservative/gc.d
Original file line number Diff line number Diff line change
Expand Up @@ -2384,6 +2384,14 @@ struct Gcx
*/
size_t fullcollect(bool nostack = false) nothrow
{
// It is possible that `fullcollect` will be called from a thread which
// is not yet registered in runtime (because allocating `new Thread` is
// part of `thread_attachThis` implementation). In that case it is
// better not to try actually collecting anything

if (Thread.getThis() is null)
return 0;

MonoTime start, stop, begin;

if (config.profile)
Expand Down
7 changes: 6 additions & 1 deletion test/thread/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
include ../common.mak

TESTS:=fiber_guard_page
TESTS:=fiber_guard_page external_threads

.PHONY: all clean
all: $(addprefix $(ROOT)/,$(addsuffix .done,$(TESTS)))
Expand All @@ -11,6 +11,11 @@ $(ROOT)/fiber_guard_page.done: $(ROOT)/%.done : $(ROOT)/%
$(QUIET)$(TIMELIMIT)$(ROOT)/$* $(RUN_ARGS); rc=$$?; [ $$rc -eq 139 ] || [ $$rc -eq 138 ]
@touch $@

$(ROOT)/external_threads.done: $(ROOT)/%.done : $(ROOT)/%
@echo Testing $*
$(QUIET)$(TIMELIMIT)$(ROOT)/$*
@touch $@

$(ROOT)/%: $(SRC)/%.d
$(QUIET)$(DMD) $(DFLAGS) -of$@ $<

Expand Down
22 changes: 22 additions & 0 deletions test/thread/src/external_threads.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import core.sys.posix.pthread;
import core.memory;

extern(C)
void* entry_point(void*)
{
// try collecting - GC must ignore this call because this thread
// is not registered in runtime
GC.collect();
return null;
}

void main()
{
// allocate some garbage
auto x = new int[1000];

pthread_t thread;
auto status = pthread_create(&thread, null, &entry_point, null);
assert(status == 0);
pthread_join(thread, null);
}