Skip to content

Commit 8ce5041

Browse files
committed
Optimize error log of failed thread creation, fix #4202
1 parent 1ec3202 commit 8ce5041

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

include/swoole_coroutine.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,17 @@ class Coroutine {
102102
static void bailout(BailoutCallback func);
103103

104104
static inline long create(const coroutine_func_t &fn, void *args = nullptr) {
105+
#ifdef SW_USE_THREAD_CONTEXT
106+
try {
107+
return (new Coroutine(fn, args))->run();
108+
} catch (const std::system_error& e) {
109+
swoole_set_last_error(e.code().value());
110+
swWarn("failed to create coroutine, Error: %s[%d]", e.what(), swoole_get_last_error());
111+
return -1;
112+
}
113+
#else
105114
return (new Coroutine(fn, args))->run();
115+
#endif
106116
}
107117

108118
static void activate();

0 commit comments

Comments
 (0)