0 branches 0 tags
43 44
45
46 47
Move thread creation into cor_platform
on 8:04 AM Oct 21 2025
trunk/coroutine/asleep.c
44
45
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#include "asleep.h"
#include "task.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <math.h>
#include <string.h>
#include "cor_platform.h"
typedef struct Loop_Timer {
int64_t when;
Future *who;
} Loop_Timer;
typedef struct _ASleep {
_Cor_Mutex mutex;
unsigned users;
Loop_Timer *sleepers;
int lo;
int hi;
int max;
_Cor_Semaphore sem;
bool sleeploop_cancel;
pthread_t sleeploop;
bool started;
} _ASleep;
static _ASleep asleep;
static void *ASleep_Sleeper(void *param);
static void ASleep_ctor(
_ASleep *me
){
int r;
me->sleepers = NULL;
me->lo = 0;
me->hi = 0;
me->max = 0;
_Cor_Mutex_ctor(&me->mutex);
_Cor_Semaphore_ctor(&me->sem);
me->sleeploop_cancel = false;
r = pthread_create(&me->sleeploop, NULL, ASleep_Sleeper, me);
assert(r == 0);
me->started = true;
}
static void ASleep_dtor(
_ASleep *me
){
int r;
me->started = false;
me->sleeploop_cancel = true;
_Cor_Semaphore_Signal(&me->sem);
r = pthread_join(me->sleeploop, NULL);
assert(r == 0);
_Cor_Sempahore_dtor(&me->sem);
_Cor_Mutex_dtor(&me->mutex);
free(me->sleepers);
}
void ASleep_StartSystem(){
ASleep_ctor(&asleep);
}
void ASleep_StopSystem(){
ASleep_dtor(&asleep);
}
static void ASleep_AddSleeper(
_ASleep *me,
int64_t when,
Future *who
){
_Cor_Mutex_Lock(&me->mutex);
int nsleepers;
if (me->lo <= me->hi){
int nsleepers = me->hi - me->lo;
// ensure there's always an empty slot so that lo == hi always means no sleepers
if (nsleepers+1 >= me->max) {
me->max = (me->max == 0) ? 4 : me->max * 2;
me->sleepers = realloc(me->sleepers, me->max * sizeof(Loop_Timer));
assert(me->sleepers);
}
} else {
nsleepers = me->hi + me->max - me->lo;
// ensure there's always an empty slot so that lo == hi always means no sleepers
if (nsleepers+1 >= me->max) {
int oldmax = me->max;
me->max = (me->max == 0) ? 4 : me->max * 2;
me->sleepers = realloc(me->sleepers, me->max * sizeof(Loop_Timer));
assert(me->sleepers);
memmove(&me->sleepers[me->lo], &me->lo + me->max - oldmax, sizeof(*me->sleepers) * oldmax - me->lo);
me->lo += me->max - oldmax;
}
}
// insertion sort - we're assuming there's not going to be many sleepers active at once
int i;
int nexti;
for (i = me->hi; i != me->lo; i = nexti){
nexti = i-1;
if (i < 0){
nexti += me->max;
}
if (me->sleepers[nexti].when <= when){
break;
}
me->sleepers[i] = me->sleepers[nexti];
}
me->sleepers[i].when = when;
me->sleepers[i].who = who;
me->hi += 1;
if (me->hi >= me->max){
me->hi -= me->max;
}
_Cor_Mutex_Unlock(&me->mutex);
_Cor_Semaphore_Signal(&me->sem);
}
static void ASleep_RemoveSleeper(
_ASleep *me,
int64_t when,
Future *who
){
_Cor_Mutex_Lock(&me->mutex);
int i;
for (i = me->lo; i != me->hi; ){
if (me->sleepers[i].when == when && me->sleepers[i].who == who){
int previ = i;
i += 1;
if (i >= me->max){
i -= me->max;
}
for (; i != me->hi; ){
me->sleepers[previ] = me->sleepers[i];
previ = i;
i += 1;
if (i >= me->max){
i -= me->max;
}
}
me->hi = previ;
break;
}
i += 1;
if (i >= me->max){
i -= me->max;
}
}
_Cor_Mutex_Unlock(&me->mutex);
_Cor_Semaphore_Signal(&me->sem);
}
static void *ASleep_Sleeper(
void *param
){
_ASleep *me = (_ASleep *)param;
while (!me->sleeploop_cancel){
_Cor_Mutex_Lock(&me->mutex);
bool got_one;
if (me->lo != me->hi){
int64_t when = me->sleepers[0].when;
_Cor_Mutex_Unlock(&me->mutex);
got_one = _Cor_Semaphore_Wait(&me->sem, when);
} else {
_Cor_Mutex_Unlock(&me->mutex);
got_one = _Cor_Semaphore_Wait(&me->sem, -1);
}
if (!got_one){
// timed out, so...
// issue any due timers
int64_t now = _Cor_Realtime_Now();
while(me->lo != me->hi && me->sleepers[me->lo].when <= now) {
Future *fut = me->sleepers[me->lo].who;
me->lo += 1;
if (me->lo >= me->max){
me->lo -= me->max;
}
_Cor_Mutex_Unlock(&me->mutex);
Future_SetResult(fut, false, NULL);
_Cor_Mutex_Lock(&me->mutex);
now = _Cor_Realtime_Now();
}
_Cor_Mutex_Unlock(&me->mutex);
}
}
return NULL;
}
// value is a pointer to a float delay in seconds
bool ASleep(
float delay,
void **value
){
assert(current_task && asleep.started);
if (delay < 0){
delay = 0;
}
int64_t endtime = _Cor_Realtime_Now() + (int64_t)(delay * 1000000000);
Future fut;
Future_ctor(&fut);
ASleep_AddSleeper(&asleep, endtime, &fut);
bool res = Future_Await(&fut, value);
ASleep_RemoveSleeper(&asleep, endtime, &fut);
Future_dtor(&fut);
return res;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#include "asleep.h"
#include "task.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <math.h>
#include <string.h>
#include "cor_platform.h"
typedef struct Loop_Timer {
int64_t when;
Future *who;
} Loop_Timer;
typedef struct _ASleep {
_Cor_Mutex mutex;
unsigned users;
Loop_Timer *sleepers;
int lo;
int hi;
int max;
_Cor_Semaphore sem;
bool sleeploop_cancel;
_Cor_Thread sleeploop;
bool started;
} _ASleep;
static _ASleep asleep;
static void *ASleep_Sleeper(void *param);
static void ASleep_ctor(
_ASleep *me
){
me->sleepers = NULL;
me->lo = 0;
me->hi = 0;
me->max = 0;
_Cor_Mutex_ctor(&me->mutex);
_Cor_Semaphore_ctor(&me->sem);
me->sleeploop_cancel = false;
_Cor_Thread_ctor(&me->sleeploop, ASleep_Sleeper, me);
me->started = true;
}
static void ASleep_dtor(
_ASleep *me
){
me->started = false;
me->sleeploop_cancel = true;
_Cor_Semaphore_Signal(&me->sem);
_Cor_Thread_Join(&me->sleeploop);
_Cor_Thread_dtor(&me->sleeploop);
_Cor_Sempahore_dtor(&me->sem);
_Cor_Mutex_dtor(&me->mutex);
free(me->sleepers);
}
void ASleep_StartSystem(){
ASleep_ctor(&asleep);
}
void ASleep_StopSystem(){
ASleep_dtor(&asleep);
}
static void ASleep_AddSleeper(
_ASleep *me,
int64_t when,
Future *who
){
_Cor_Mutex_Lock(&me->mutex);
int nsleepers;
if (me->lo <= me->hi){
int nsleepers = me->hi - me->lo;
// ensure there's always an empty slot so that lo == hi always means no sleepers
if (nsleepers+1 >= me->max) {
me->max = (me->max == 0) ? 4 : me->max * 2;
me->sleepers = realloc(me->sleepers, me->max * sizeof(Loop_Timer));
assert(me->sleepers);
}
} else {
nsleepers = me->hi + me->max - me->lo;
// ensure there's always an empty slot so that lo == hi always means no sleepers
if (nsleepers+1 >= me->max) {
int oldmax = me->max;
me->max = (me->max == 0) ? 4 : me->max * 2;
me->sleepers = realloc(me->sleepers, me->max * sizeof(Loop_Timer));
assert(me->sleepers);
memmove(&me->sleepers[me->lo], &me->lo + me->max - oldmax, sizeof(*me->sleepers) * oldmax - me->lo);
me->lo += me->max - oldmax;
}
}
// insertion sort - we're assuming there's not going to be many sleepers active at once
int i;
int nexti;
for (i = me->hi; i != me->lo; i = nexti){
nexti = i-1;
if (i < 0){
nexti += me->max;
}
if (me->sleepers[nexti].when <= when){
break;
}
me->sleepers[i] = me->sleepers[nexti];
}
me->sleepers[i].when = when;
me->sleepers[i].who = who;
me->hi += 1;
if (me->hi >= me->max){
me->hi -= me->max;
}
_Cor_Mutex_Unlock(&me->mutex);
_Cor_Semaphore_Signal(&me->sem);
}
static void ASleep_RemoveSleeper(
_ASleep *me,
int64_t when,
Future *who
){
_Cor_Mutex_Lock(&me->mutex);
int i;
for (i = me->lo; i != me->hi; ){
if (me->sleepers[i].when == when && me->sleepers[i].who == who){
int previ = i;
i += 1;
if (i >= me->max){
i -= me->max;
}
for (; i != me->hi; ){
me->sleepers[previ] = me->sleepers[i];
previ = i;
i += 1;
if (i >= me->max){
i -= me->max;
}
}
me->hi = previ;
break;
}
i += 1;
if (i >= me->max){
i -= me->max;
}
}
_Cor_Mutex_Unlock(&me->mutex);
_Cor_Semaphore_Signal(&me->sem);
}
static void *ASleep_Sleeper(
void *param
){
_ASleep *me = (_ASleep *)param;
while (!me->sleeploop_cancel){
_Cor_Mutex_Lock(&me->mutex);
bool got_one;
if (me->lo != me->hi){
int64_t when = me->sleepers[0].when;
_Cor_Mutex_Unlock(&me->mutex);
got_one = _Cor_Semaphore_Wait(&me->sem, when);
} else {
_Cor_Mutex_Unlock(&me->mutex);
got_one = _Cor_Semaphore_Wait(&me->sem, -1);
}
if (!got_one){
// timed out, so...
// issue any due timers
int64_t now = _Cor_Realtime_Now();
while(me->lo != me->hi && me->sleepers[me->lo].when <= now) {
Future *fut = me->sleepers[me->lo].who;
me->lo += 1;
if (me->lo >= me->max){
me->lo -= me->max;
}
_Cor_Mutex_Unlock(&me->mutex);
Future_SetResult(fut, false, NULL);
_Cor_Mutex_Lock(&me->mutex);
now = _Cor_Realtime_Now();
}
_Cor_Mutex_Unlock(&me->mutex);
}
}
return NULL;
}
// value is a pointer to a float delay in seconds
bool ASleep(
float delay,
void **value
){
assert(current_task && asleep.started);
if (delay < 0){
delay = 0;
}
int64_t endtime = _Cor_Realtime_Now() + (int64_t)(delay * 1000000000);
Future fut;
Future_ctor(&fut);
ASleep_AddSleeper(&asleep, endtime, &fut);
bool res = Future_Await(&fut, value);
ASleep_RemoveSleeper(&asleep, endtime, &fut);
Future_dtor(&fut);
return res;
}
trunk/coroutine/cor_platform.c
44
45
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include "cor_platform.h"
#include <assert.h>
#include "timespec_utils.h"
void _Cor_Mutex_ctor(_Cor_Mutex *mut){
int r;
r = pthread_mutex_init(&mut->mut, NULL);
assert(r == 0);
}
void _Cor_Mutex_dtor(_Cor_Mutex *mut){
int r;
r = pthread_mutex_destroy(&mut->mut);
assert(r == 0);
}
void _Cor_Mutex_Lock(_Cor_Mutex *mut){
int r;
r = pthread_mutex_lock(&mut->mut);
assert(r == 0);
}
void _Cor_Mutex_Unlock(_Cor_Mutex *mut){
int r;
r = pthread_mutex_unlock(&mut->mut);
assert(r == 0);
}
int64_t _Cor_Realtime_Now(){
int r;
struct timespec now;
r = clock_gettime(CLOCK_REALTIME, &now);
assert(r == 0);
return int64_ns_from_timespec(now);
}
void _Cor_Semaphore_ctor(_Cor_Semaphore *sem){
int r;
r = pthread_mutex_init(&sem->mut, NULL);
assert(r == 0);
r = pthread_cond_init(&sem->cond, NULL);
assert(r == 0);
sem->count = 0;
}
void _Cor_Sempahore_dtor(_Cor_Semaphore *sem){
int r;
r = pthread_cond_destroy(&sem->cond);
assert(r == 0);
r = pthread_mutex_destroy(&sem->mut);
assert(r == 0);
}
// timeout_when < 0 means 'wait forever'
// Returns true for success, false for timeout
bool _Cor_Semaphore_Wait(_Cor_Semaphore *sem, int64_t timeout_when){
int r;
r = pthread_mutex_lock(&sem->mut);
assert(r == 0);
if (sem->count == 0) {
if (timeout_when >= 0) {
struct timespec ts = timespec_from_int64_ns(timeout_when);
r = pthread_cond_timedwait(&sem->cond, &sem->mut, &ts);
}
else {
r = pthread_cond_wait(&sem->cond, &sem->mut);
}
}
assert(r == 0 || r == ETIMEDOUT);
bool res;
if (sem->count > 0) {
sem->count--;
res = true;
} else {
res = false;
}
r = pthread_mutex_unlock(&sem->mut);
assert(r == 0);
return res;
}
void _Cor_Semaphore_Signal(_Cor_Semaphore *sem){
int r;
r = pthread_mutex_lock(&sem->mut);
assert(r == 0);
sem->count++;
r = pthread_cond_signal(&sem->cond);
assert(r == 0);
r = pthread_mutex_unlock(&sem->mut);
assert(r == 0);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include "cor_platform.h"
#include <assert.h>
#include "timespec_utils.h"
#include <stdio.h>
void _Cor_Mutex_ctor(_Cor_Mutex *mut){
int r;
r = pthread_mutex_init(&mut->mut, NULL);
assert(r == 0);
}
void _Cor_Mutex_dtor(_Cor_Mutex *mut){
int r;
r = pthread_mutex_destroy(&mut->mut);
assert(r == 0);
}
void _Cor_Mutex_Lock(_Cor_Mutex *mut){
int r;
r = pthread_mutex_lock(&mut->mut);
assert(r == 0);
}
void _Cor_Mutex_Unlock(_Cor_Mutex *mut){
int r;
r = pthread_mutex_unlock(&mut->mut);
assert(r == 0);
}
int64_t _Cor_Realtime_Now(){
int r;
struct timespec now;
r = clock_gettime(CLOCK_REALTIME, &now);
assert(r == 0);
return int64_ns_from_timespec(now);
}
void _Cor_Semaphore_ctor(_Cor_Semaphore *sem){
int r;
r = pthread_mutex_init(&sem->mut, NULL);
assert(r == 0);
r = pthread_cond_init(&sem->cond, NULL);
assert(r == 0);
sem->count = 0;
}
void _Cor_Sempahore_dtor(_Cor_Semaphore *sem){
int r;
r = pthread_cond_destroy(&sem->cond);
assert(r == 0);
r = pthread_mutex_destroy(&sem->mut);
assert(r == 0);
}
// timeout_when < 0 means 'wait forever'
// Returns true for success, false for timeout
bool _Cor_Semaphore_Wait(_Cor_Semaphore *sem, int64_t timeout_when){
int r;
r = pthread_mutex_lock(&sem->mut);
assert(r == 0);
if (sem->count == 0) {
if (timeout_when >= 0) {
struct timespec ts = timespec_from_int64_ns(timeout_when);
r = pthread_cond_timedwait(&sem->cond, &sem->mut, &ts);
}
else {
r = pthread_cond_wait(&sem->cond, &sem->mut);
}
}
assert(r == 0 || r == ETIMEDOUT);
bool res;
if (sem->count > 0) {
sem->count--;
res = true;
} else {
res = false;
}
r = pthread_mutex_unlock(&sem->mut);
assert(r == 0);
return res;
}
void _Cor_Semaphore_Signal(_Cor_Semaphore *sem){
int r;
r = pthread_mutex_lock(&sem->mut);
assert(r == 0);
sem->count++;
r = pthread_cond_signal(&sem->cond);
assert(r == 0);
r = pthread_mutex_unlock(&sem->mut);
assert(r == 0);
}
void _Cor_Thread_ctor(_Cor_Thread *th, void *(*fn)(void *), void *param){
int r;
th->joined = false;
r = pthread_create(&th->th, NULL, fn, param);
assert(r == 0);
}
void _Cor_Thread_dtor(_Cor_Thread *th){
int r;
if (!th->joined){
r = pthread_detach(th->th);
assert(r == 0);
}
}
void *_Cor_Thread_Join(_Cor_Thread *th){
int r;
void *res;
r = pthread_join(th->th, &res);
assert(r == 0);
th->joined = true;
return res;
}
trunk/include/cor_platform.h
44
45
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#ifndef COR_PLATFORM_H
#define COR_PLATFORM_H
// platform specific parts collected together
#include <stdbool.h>
#include <pthread.h>
#include <errno.h>
// inspired by CPython to achieve platform indenpendence for thread local variables
#ifdef thread_local
#define _Cor_thread_local thread_local
#elif __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_THREADS__)
#define _Cor_thread_local _Thread_local
#elif defined(_MSC_VER) /* AKA NT_THREADS */
#define _Cor_thread_local __declspec(thread)
#elif defined(__GNUC__) /* includes clang */
#define _Cor_thread_local __thread
#else
#define _Cor_thread_local
#endif
// Non-reentrant Mutexes
typedef struct _Cor_Mutex {
pthread_mutex_t mut;
} _Cor_Mutex;
void _Cor_Mutex_ctor(_Cor_Mutex *);
void _Cor_Mutex_dtor(_Cor_Mutex *);
void _Cor_Mutex_Lock(_Cor_Mutex *);
void _Cor_Mutex_Unlock(_Cor_Mutex *);
// The 'now' to use for _Cor_Semaphore_Wait, in ns.
int64_t _Cor_Realtime_Now();
typedef struct _Cor_Semaphore {
pthread_mutex_t mut;
pthread_cond_t cond;
unsigned count;
} _Cor_Semaphore;
void _Cor_Semaphore_ctor(_Cor_Semaphore *sem);
void _Cor_Sempahore_dtor(_Cor_Semaphore *sem);
// timeout_when < 0 means 'wait forever'
// Returns true for success, false for timeout
bool _Cor_Semaphore_Wait(_Cor_Semaphore *sem, int64_t timeout_when);
void _Cor_Semaphore_Signal(_Cor_Semaphore *sem);
#endif
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef COR_PLATFORM_H
#define COR_PLATFORM_H
// platform specific parts collected together
#include <stdbool.h>
#include <pthread.h>
#include <errno.h>
// inspired by CPython to achieve platform indenpendence for thread local variables
#ifdef thread_local
#define _Cor_thread_local thread_local
#elif __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_THREADS__)
#define _Cor_thread_local _Thread_local
#elif defined(_MSC_VER) /* AKA NT_THREADS */
#define _Cor_thread_local __declspec(thread)
#elif defined(__GNUC__) /* includes clang */
#define _Cor_thread_local __thread
#else
#define _Cor_thread_local
#endif
// Non-reentrant Mutexes
typedef struct _Cor_Mutex {
pthread_mutex_t mut;
} _Cor_Mutex;
void _Cor_Mutex_ctor(_Cor_Mutex *);
void _Cor_Mutex_dtor(_Cor_Mutex *);
void _Cor_Mutex_Lock(_Cor_Mutex *);
void _Cor_Mutex_Unlock(_Cor_Mutex *);
// The 'now' to use for _Cor_Semaphore_Wait, in ns.
int64_t _Cor_Realtime_Now();
typedef struct _Cor_Semaphore {
pthread_mutex_t mut;
pthread_cond_t cond;
unsigned count;
} _Cor_Semaphore;
void _Cor_Semaphore_ctor(_Cor_Semaphore *sem);
void _Cor_Sempahore_dtor(_Cor_Semaphore *sem);
// timeout_when < 0 means 'wait forever'
// Returns true for success, false for timeout
bool _Cor_Semaphore_Wait(_Cor_Semaphore *sem, int64_t timeout_when);
void _Cor_Semaphore_Signal(_Cor_Semaphore *sem);
typedef struct _Cor_Thread {
pthread_t th;
bool joined;
} _Cor_Thread;
void _Cor_Thread_ctor(_Cor_Thread *, void *(*)(void *), void *);
void _Cor_Thread_dtor(_Cor_Thread *);
void *_Cor_Thread_Join(_Cor_Thread *);
#endif