@@ -558,6 +558,8 @@ version (LDC)
558
558
559
559
version (Android ) version = CheckFiberMigration;
560
560
561
+ version (AArch64 ) version = CheckFiberMigration;
562
+
561
563
// Fiber migration across threads is (probably) not possible with ASan fakestack enabled (different parts of the stack
562
564
// will contain fakestack pointers that were created on different threads...)
563
565
version (SupportSanitizers) version = CheckFiberMigration;
@@ -1132,6 +1134,16 @@ class Fiber
1132
1134
*/
1133
1135
static Fiber getThis () @safe nothrow @nogc
1134
1136
{
1137
+ // LDC NOTE:
1138
+ // Currently, it is not safe to migrate fibers across threads when they
1139
+ // use TLS at all, as LLVM might cache the TLS address lookup across a
1140
+ // context switch (see https://github.com/ldc-developers/ldc/issues/666).
1141
+ // Preventing inlining of this function, as well as switch{In,Out}
1142
+ // below, enables users to do this at least as long as they are very
1143
+ // careful about accessing TLS data themselves (such as in the shared
1144
+ // fiber unittest below, which tends to sporadically crash with enabled
1145
+ // optimizations if this prevent-inlining workaround is removed).
1146
+ version (LDC ) pragma (inline, false );
1135
1147
return sm_this;
1136
1148
}
1137
1149
@@ -1951,6 +1963,7 @@ private:
1951
1963
//
1952
1964
final void switchIn () nothrow @nogc
1953
1965
{
1966
+ // see note in getThis()
1954
1967
version (LDC ) pragma (inline, false );
1955
1968
1956
1969
ThreadBase tobj = ThreadBase.getThis();
@@ -2044,6 +2057,7 @@ private:
2044
2057
//
2045
2058
final void switchOut () nothrow @nogc
2046
2059
{
2060
+ // see note in getThis()
2047
2061
version (LDC ) pragma (inline, false );
2048
2062
2049
2063
ThreadBase tobj = m_curThread;
@@ -2320,7 +2334,7 @@ unittest
2320
2334
fibs[idx].call();
2321
2335
cont |= fibs[idx].state != Fiber .State.TERM ;
2322
2336
}
2323
- locks[idx] = false ;
2337
+ locks[idx].atomicStore( false ) ;
2324
2338
}
2325
2339
else
2326
2340
{
0 commit comments