|
|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
如下所示,调用pthread_join以后,报错,有大佬知道解决吗?
" ~2 M! C- O R% i
- i' o' Y; W+ r2 I) nmsh />5 _. W* G3 B! C* N
msh />& u0 F+ [' n# {; u
msh />* o3 _7 }. @" O T- w F& w
msh />. b; r: l3 Y. W
msh />
9 `4 h6 a' r3 U6 r" `5 B d\ | /) ~( [1 c' p0 ?7 c& b# ?, v; Y
- n/ q2 B8 u# i3 s" M# ART - Thread Operating System0 K& D, M3 I6 l# f- I5 P: r8 |% q
/ | \ 4.1.0 build Jun 24 2022 16:22:28
3 i' `) w, f, V ]& n2006 - 2022 Copyright by RT-Thread team
: ?# f X' s, X' l/ J! o6 xpthread_create success
2 y' V; f- h- {7 d4 zi'm thread1 and i will detach myself!; d) \/ R- S j: T
posix thread 0
# `, A2 [9 S' ?. b7 y: K0 eposix thread 1) M, C' ?5 e. b, Z9 x A, x
posix thread 2
" L' ^. e; `$ n; p Bposix thread 3+ F* y V8 D, s
posix thread 4( H6 R: a$ l+ U) ?% n
thread1 exited!
5 @7 T$ S0 L: X1 W4 yposix_thread_init exit
+ P- e1 L6 i8 s5 k Hmsh />(small_mem != RT_NULL) assertion failed at function:rt_smem_free, line number:532
7 k0 d8 S8 ? e" ~+ G5 ~#include <pthread.h>2 r. o" x9 Z- S; P3 T
#include <unistd.h>% C! w/ H7 S# z/ J, @
#include <stdio.h>
4 h( |+ \) t0 |7 d% f Qstatic pthread_t tid1;% E2 z/ T. n; _8 {
static void* thread1_entry(void *param)
! s7 V2 y4 c X* v2 I2 q{
/ g# R7 ^& I8 |/ Q7 xprintf("i'm thread1 and i will detach myself!\n"); m. K# O1 G7 v$ @; M( n, T
for(int i=0; i<5; i++)0 b' l0 e6 w: G* T" F2 {6 a$ N% G
{
4 d% m3 O) O, Q* hprintf("posix thread %d\n", i);3 V$ f2 P6 o& n! c
sleep(1);
* }# ?5 K ?$ ?' D) R, U+ [) b}( i2 L5 `" F7 g# ^7 c
printf("thread1 exited!\n");
1 W: G8 e% }5 {. i `return NULL;
3 n0 E4 M) T2 S; @}
0 n, n" w/ e) s% u2 z$ Ystatic int posix_thread_init(void)
# l4 B6 B# ^9 Q; ?{
) d" }! c% ~$ ^int result;
- @" M, f2 |; q4 @) _0 f. i5 j& lresult = pthread_create(&tid1, NULL, thread1_entry, NULL); q3 a: j3 A% c. ~* [' Y# y5 d) v
if( result == 0 ), H& e9 e: N& o
{
( ?) Y+ O8 M9 x1 V( i& ]) Pprintf("pthread_create success\n");
. o J! V2 h, J+ o& [6 C- j9 @}
# G7 N/ q9 S6 x7 l# jelse
8 d, `" g1 ^3 C) ]( d{
9 I5 o% H; z) g+ _printf("pthread_create fail\n");1 C; v) b0 b) x2 k7 U, {
}
$ O% r- A- J5 K. L" e$ D) r- n) Spthread_join(tid1, NULL);
2 U8 ^4 ^4 [$ J+ O( Uprintf("posix_thread_init exit\n");
% |/ q6 a P- T- Q6 j3 R+ ?return 0;
+ n6 U( x2 U6 J) t- ?}/ R# T% \- O! W5 U0 h; [
INIT_APP_EXPORT(posix_thread_init);
! y' @$ ]8 i$ P9 e- n7 n! C |
|