@@ -147,12 +147,6 @@ void task_exit(rust_closure_env *env, int rval, rust_task *task) {
147
147
// env->td->free_glue(NULL, task, NULL, env->td->first_param, env);
148
148
task->free (env);
149
149
}
150
- task->die ();
151
- task->lock .lock ();
152
- task->notify_tasks_waiting_to_join ();
153
- task->lock .unlock ();
154
-
155
- task->yield (1 );
156
150
}
157
151
158
152
extern " C" CDECL
@@ -161,8 +155,37 @@ void task_start_wrapper(spawn_args *a)
161
155
rust_task *task = a->task ;
162
156
int rval = 42 ;
163
157
164
- a->f (&rval, task, a->a3 , a->a4 );
165
- task_exit ((rust_closure_env*)a->a3 , rval, task);
158
+ bool failed = false ;
159
+ try {
160
+ a->f (&rval, task, a->a3 , a->a4 );
161
+ } catch (rust_task *ex) {
162
+ A (task->sched , ex == task,
163
+ " Expected this task to be thrown for unwinding" );
164
+ failed = true ;
165
+ }
166
+
167
+ rust_closure_env* env = (rust_closure_env*)a->a3 ;
168
+ if (env) {
169
+ // free the environment.
170
+ I (task->sched , 1 == env->ref_count ); // the ref count better be 1
171
+ // env->td->drop_glue(NULL, task, NULL, env->td->first_param, env);
172
+ // env->td->free_glue(NULL, task, NULL, env->td->first_param, env);
173
+ task->free (env);
174
+ }
175
+
176
+ if (failed) {
177
+ #ifndef __WIN32__
178
+ task->conclude_failure ();
179
+ #else
180
+ A (task->sched , false , " Shouldn't happen" );
181
+ #endif
182
+ } else {
183
+ task->die ();
184
+ task->lock .lock ();
185
+ task->notify_tasks_waiting_to_join ();
186
+ task->lock .unlock ();
187
+ task->yield (1 );
188
+ }
166
189
}
167
190
168
191
/* We spawn a rust (fastcc) function through a CDECL function
@@ -276,6 +299,15 @@ rust_task::fail() {
276
299
// See note in ::kill() regarding who should call this.
277
300
DLOG (sched, task, " task %s @0x%" PRIxPTR " failing" , name, this );
278
301
backtrace ();
302
+ #ifndef __WIN32__
303
+ throw this ;
304
+ #else
305
+ conclude_failure ();
306
+ #endif
307
+ }
308
+
309
+ void
310
+ rust_task::conclude_failure () {
279
311
die ();
280
312
// Unblock the task so it can unwind.
281
313
unblock ();
0 commit comments