You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Thread: Implement more functionality
- Eliminate _compiler_crash_fix() as no crashes are observed anymore.
- Re-enable TestThread.swift test cases.
* Update implementation status for Thread to Complete
* Thread: Improve tests
- Fix NSCondition.wait(until:) to correctly calculate the timespec
to use for the timeout.
- Fix test_threadStart() and test_mainThread() to eliminate the
`started' flag which could have a race condition and instead
use NSCondition.wait(until:) to timeout the test thread, in case
it does not start up or call the broadcast() function.
// !!! NSThread's mainThread property is incorrectly exported as "main", which conflicts with its "main" method.
71
-
openclassvarmainThread:Thread{NSUnimplemented()}
71
+
privatestaticlet_mainThread:Thread={
72
+
varthread=Thread(thread: _CFMainPThread)
73
+
thread._status =.executing
74
+
return thread
75
+
}()
76
+
77
+
openclassvarmainThread:Thread{
78
+
return _mainThread
79
+
}
80
+
72
81
73
82
/// Alternative API for detached thread creation
74
83
/// - Experiment: This is a draft API currently under consideration for official import into Foundation as a suitable alternative to creation via selector
@@ -77,11 +86,11 @@ open class Thread : NSObject {
77
86
lett=Thread(block: block)
78
87
t.start()
79
88
}
80
-
89
+
81
90
openclassfunc isMultiThreaded()->Bool{
82
91
returntrue
83
92
}
84
-
93
+
85
94
openclassfunc sleep(until date:Date){
86
95
letstart_ut=CFGetSystemUptime()
87
96
letstart_at=CFAbsoluteTimeGetCurrent()
@@ -127,9 +136,10 @@ open class Thread : NSObject {
127
136
}
128
137
129
138
openclassfunc exit(){
139
+
Thread.current._status =.finished
130
140
pthread_exit(nil)
131
141
}
132
-
142
+
133
143
internalvar_main:()->Void={}
134
144
#if os(OSX) || os(iOS) || CYGWIN
135
145
privatevar_thread:pthread_t?=nil
@@ -145,20 +155,20 @@ open class Thread : NSObject {
145
155
internalvar_cancelled=false
146
156
/// - Note: this differs from the Darwin implementation in that the keys must be Strings
147
157
openvarthreadDictionary=[String : Any]()
148
-
158
+
149
159
internalinit(thread:pthread_t){
150
160
// Note: even on Darwin this is a non-optional pthread_t; this is only used for valid threads, which are never null pointers.
151
161
_thread = thread
152
162
}
153
-
163
+
154
164
publicoverrideinit(){
155
165
let _ =withUnsafeMutablePointer(to:&_attr){ attr in
0 commit comments