|
|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
如下所示,调用pthread_join以后,报错,有大佬知道解决吗?
7 j2 H# e0 U9 ~0 l# V6 c
X% X7 }+ j* U; a% d( _& B. tmsh />* r! U5 t5 E6 k" n7 ^$ |9 G9 m0 |
msh />1 a% N: \( ~6 `8 ~ K8 @& H
msh />
1 {. c* Q& B, W, m+ O1 V3 }5 t& n1 ?msh />$ o9 t& M9 L& \) u n4 i2 W( s
msh />7 q, f: ?; i8 {
\ | /
& q" f% | l5 S" ?
" T' J1 m$ c2 P; T' m8 TRT - Thread Operating System
" w. R. ]0 b* z" d* y: V$ C6 k9 Q8 I/ | \ 4.1.0 build Jun 24 2022 16:22:28
6 v7 ]: Q7 M P8 @+ h/ V! L1 K$ U6 F2006 - 2022 Copyright by RT-Thread team) x8 w& S) G0 t; y V2 `
pthread_create success
! w$ l: v. [; X" e: Ai'm thread1 and i will detach myself!
2 p! z" b& {' n5 V3 g4 vposix thread 0
6 A7 D4 [# g) ^: u! Z5 vposix thread 10 G* b1 ~; x$ s4 G, e' d
posix thread 2
$ S. V5 Z. M% j$ Yposix thread 3' @# s5 i2 s& U9 ?- n
posix thread 42 M% N8 F- X6 s6 Z; r0 c0 G
thread1 exited!3 o6 J/ N9 O* q0 h2 A {: Z k7 L0 j
posix_thread_init exit
* q5 y% z' {6 L! Z& K* ^msh />(small_mem != RT_NULL) assertion failed at function:rt_smem_free, line number:532
0 \4 l8 @7 e# Z; |#include <pthread.h>
* k( C; ?5 Z2 U5 z: O! ^1 W- h#include <unistd.h>
) D7 P2 Q" N; B4 x#include <stdio.h>9 A1 r& ~( J+ ]- a, {+ e. M4 h
static pthread_t tid1;$ f3 r, [' Y- F% Z! C/ z6 j
static void* thread1_entry(void *param)
9 A8 P; r9 \: A{
! q0 D1 I- i& \: g2 ?4 C. P8 Iprintf("i'm thread1 and i will detach myself!\n");& q8 F9 E: n, g0 b/ z: c$ v" C
for(int i=0; i<5; i++)
9 c- B5 d! L3 @( E6 ~4 P{7 h9 G- `% A" F' ~
printf("posix thread %d\n", i);+ t8 P* G$ r6 m& N
sleep(1);
7 z% S+ o5 ]/ a}8 F/ x9 O* X" ^$ q" a
printf("thread1 exited!\n");
2 {) t8 c; ?" S. X% dreturn NULL;
) f E X$ W, m: i, L}
0 b! K4 U" ~/ X9 ?static int posix_thread_init(void)
; d b! H1 b h{
% b! ~' w: Z* x5 h2 Oint result;$ x4 ^* Y5 f2 x9 B
result = pthread_create(&tid1, NULL, thread1_entry, NULL);
6 T4 O3 l4 |4 E+ q! xif( result == 0 )
1 z3 s$ m& g4 L) K/ F{
% N- T; ^" i, q( i1 o$ G5 iprintf("pthread_create success\n");0 E, A v. s3 a& ~) w, v7 B
}
/ P- ?' Q0 n: Aelse
3 J8 | f8 H# F; e% O' C{4 U' l; ]0 N) D9 d2 l6 L
printf("pthread_create fail\n");9 E) F G* ]) q2 U/ f
}
: e8 J! n! {; L9 npthread_join(tid1, NULL);
7 l7 G6 U' T7 b& W0 x4 _8 ^* vprintf("posix_thread_init exit\n");
: G4 e! y5 q7 n. Creturn 0;! B' d' D8 H/ ?5 U! d/ v
}
. j+ _6 D& o+ v/ a4 {- U$ [INIT_APP_EXPORT(posix_thread_init);
4 h4 L) I2 v3 _4 J3 n |
|