|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
如下所示,调用pthread_join以后,报错,有大佬知道解决吗?/ V; K, p. A1 H6 V) H: E
2 [! z" `7 Z8 k0 bmsh />2 m5 Y% ~( g$ E, Z& L6 j
msh />
" ?! _) D7 Q) S' J1 |msh />
% @- |# o' z% w6 l @, kmsh />5 m7 d, Y* i& u F
msh />
7 V6 s4 F6 Q0 m m3 [' X0 X\ | /$ d' K% \4 o/ s6 G* ~0 d
' X1 s' [( L' @% t6 Q4 P1 y$ ?& KRT - Thread Operating System
; H* e8 f8 F0 v- i' e2 c7 r& O/ | \ 4.1.0 build Jun 24 2022 16:22:28* h8 Z4 s" X3 D: l% l1 G
2006 - 2022 Copyright by RT-Thread team3 Q5 ^4 P& D& N% ~! v1 S9 X
pthread_create success( x/ m7 F& d0 ]2 Q
i'm thread1 and i will detach myself! ]& Y7 ~# {; }1 T3 [
posix thread 0: K3 x( p: X m
posix thread 1
# P8 {9 J* F \; s1 G( ^posix thread 2
* c6 e- `8 o: P4 n. [! |# iposix thread 3' O, i9 P0 O! J: ^
posix thread 46 D+ W0 k+ i4 T8 K! D
thread1 exited!0 ^4 |$ T3 X4 f" l
posix_thread_init exit* E9 S8 ~, O" y A' I
msh />(small_mem != RT_NULL) assertion failed at function:rt_smem_free, line number:532
' `: V6 ?) X9 P' x- H! h- \. k#include <pthread.h>' I" Z b8 y4 I, h
#include <unistd.h>0 A6 A$ Q, O4 u1 y. ]# ^, J8 p
#include <stdio.h>
l8 \: R6 v+ t9 U6 Estatic pthread_t tid1;/ H9 A6 c' h: N
static void* thread1_entry(void *param)6 y. [; N7 V. a2 P, a
{
( {* f4 x' x0 ?! V0 E- T% @7 B1 B fprintf("i'm thread1 and i will detach myself!\n");6 m* B; |+ H! R5 ?1 h `
for(int i=0; i<5; i++)5 p) N% R! V U9 ~4 P4 I, F
{
6 l" h i& C& _2 ]& V7 Uprintf("posix thread %d\n", i);# q$ u+ Q- m7 A/ m' b
sleep(1);
$ C0 Y# i4 Y# Z' S# [& h c( V}) \7 D4 N. R4 O
printf("thread1 exited!\n");* K% }& N! r" n
return NULL;. ]" [* ]7 B& c" ~6 F, b
}
8 S, Z& L( l/ l6 \) G9 K7 }static int posix_thread_init(void)
5 ]$ ?, w( ]% n7 ^ ]{" v4 p5 J' q4 Z- c/ o: q; R( @
int result;& M& ^6 f a4 `$ S
result = pthread_create(&tid1, NULL, thread1_entry, NULL);9 L! G% z! ^ ?7 r7 @
if( result == 0 )
_2 W5 G! t* B. U6 ?4 I& ]1 Q{/ w9 z, k0 c; Z6 H$ |5 p
printf("pthread_create success\n");, ^5 t" Q8 S4 V5 N8 c
}+ O$ J8 k) s. F; t! u6 X
else" x& ^( k0 R N1 ^
{3 _: f4 D* G s4 r
printf("pthread_create fail\n");
& v4 ?' t# V, Y) n+ p5 p; `}/ @+ x, b0 b! \$ N3 {9 `
pthread_join(tid1, NULL);
6 `& f+ m6 d7 i: b2 vprintf("posix_thread_init exit\n");# X; L3 T% o$ h$ ]
return 0;
2 G" j8 z1 u0 m6 w/ ?}$ E6 _4 R+ _) ~$ g8 v
INIT_APP_EXPORT(posix_thread_init);' @( K" K2 p& B- Y5 `& S
|
|