Files
gcc-reflection/libphobos/testsuite/libphobos.thread/external_threads.d
Iain Buclaw b3b54f9c9a libphobos: Merge changes in upstream druntime testsuite
libphobos/ChangeLog:

	* libdruntime/MERGE: Merge upstream druntime d2ee11364c.
	* testsuite/libphobos.aa/test_aa.d: Add new test.
	* testsuite/libphobos.betterc/test19933.d: Adjust imports.
	* testsuite/libphobos.config/test22523.d: Likewise.
	* testsuite/libphobos.exceptions/assert_fail.d: Adjust test.
	* testsuite/libphobos.exceptions/chain.d: Adjust imports.
	* testsuite/libphobos.exceptions/future_message.d: Likewise.
	* testsuite/libphobos.exceptions/line_trace.d: Likewise.
	* testsuite/libphobos.exceptions/long_backtrace_trunc.d: Likewise.
	* testsuite/libphobos.exceptions/static_dtor.d: Likewise.
	* testsuite/libphobos.gc/forkgc.d: Likewise.
	* testsuite/libphobos.gc/precisegc.d: Likewise.
	* testsuite/libphobos.gc/recoverfree.d: Likewise.
	* testsuite/libphobos.hash/test_hash.d: Likewise.
	* testsuite/libphobos.init_fini/custom_gc.d: Likewise.
	* testsuite/libphobos.init_fini/thread_join.d: Likewise.
	* testsuite/libphobos.thread/external_threads.d: Likewise.
	* testsuite/libphobos.thread/fiber_guard_page.d: Likewise.
	* testsuite/libphobos.thread/tlsgc_sections.d: Likewise.
	* testsuite/libphobos.thread/tlsstack.d: Likewise.
	* testsuite/libphobos.unittest/customhandler.d: Likewise.
2025-03-18 18:53:11 +01:00

52 lines
1.1 KiB
D

import core.memory;
import core.sys.posix.pthread : pthread_create, pthread_join;
import core.sys.posix.sys.types : pthread_t;
import core.thread;
extern (C) void rt_moduleTlsCtor();
extern (C) void rt_moduleTlsDtor();
extern(C)
void* entry_point1(void*)
{
// try collecting - GC must ignore this call because this thread
// is not registered in runtime
GC.collect();
return null;
}
extern(C)
void* entry_point2(void*)
{
// This thread gets registered in druntime, does some work and gets
// unregistered to be cleaned up manually
thread_attachThis();
rt_moduleTlsCtor();
auto x = new int[10];
rt_moduleTlsDtor();
thread_detachThis();
return null;
}
void main()
{
// allocate some garbage
auto x = new int[1000];
{
pthread_t thread;
auto status = pthread_create(&thread, null, &entry_point1, null);
assert(status == 0);
pthread_join(thread, null);
}
{
pthread_t thread;
auto status = pthread_create(&thread, null, &entry_point2, null);
assert(status == 0);
pthread_join(thread, null);
}
}