EDA365电子论坛网
标题:
调用pthread_join以后报错有大佬知道怎么解决吗
[打印本页]
作者:
abc66
时间:
2022-9-20 11:18
标题:
调用pthread_join以后报错有大佬知道怎么解决吗
如下所示,调用pthread_join以后,报错,有大佬知道解决吗?
- [; d6 h* ~7 _
) v) y6 D* X$ J& Y( x7 Q
msh />
9 G% G: P" g/ |0 q# n
msh />
6 T# o9 C& i/ o6 l4 N/ w' b
msh />
% P: C1 G2 B# I" E
msh />
3 x' L. E+ B8 I$ ^0 l. o
msh />
. g/ J8 r# ?1 r
\ | /
9 ]/ T; R2 y4 J' y) }0 Y
+ x5 F; J* |! X I- e' c
RT - Thread Operating System
' K. h3 B* [6 k) T" B4 o
/ | \ 4.1.0 build Jun 24 2022 16:22:28
' E/ X& b3 |% V" F- b
2006 - 2022 Copyright by RT-Thread team
# {- p H! _* {% Z8 J" [0 y
pthread_create success
" k; j' S; L9 C1 s! ~" \0 i, x
i'm thread1 and i will detach myself!
- H. n( ]: z! A: \0 O1 Z
posix thread 0
% r+ a0 V+ e @/ a" q
posix thread 1
. d4 h( X, A; ?& y3 r
posix thread 2
6 ^2 W4 e Q S' J7 d; `
posix thread 3
# o5 d5 A1 f( _5 H
posix thread 4
4 B/ v' c( z0 N. t* Z8 F# o
thread1 exited!
; }1 t% q L' d/ d5 b) A6 Z: h
posix_thread_init exit
" A6 O( L. e! E5 D1 B- n
msh />(small_mem != RT_NULL) assertion failed at function:rt_smem_free, line number:532
, T A" y0 Q6 p! @( S
#include <pthread.h>
7 O; m" W9 U( ^- a+ U5 b
#include <unistd.h>
6 a! E' Y8 Y0 k, l, {3 U
#include <stdio.h>
) S g: A% h9 c
static pthread_t tid1;
2 w( w# ^, f! H/ \ Z* H2 N/ o: A
static void* thread1_entry(void *param)
+ j! i8 _ ?9 P: ^2 D! W2 ~
{
& j: R, [: @/ n' w! n1 O! Y
printf("i'm thread1 and i will detach myself!\n");
/ K. S; \9 I9 W# W5 ?
for(int i=0; i<5; i++)
8 }: h4 |, q* U9 b) K1 e
{
3 z( B' b- q5 }4 z7 {( `) B8 Q
printf("posix thread %d\n", i);
/ x% y) v3 m3 Z
sleep(1);
9 K' }$ o" Q! r! y
}
9 Z# A" v5 c5 D A; Q( m
printf("thread1 exited!\n");
7 K; V" p6 T% V# f( k2 P
return NULL;
) H& ^* [! k+ a; a0 V# b' u
}
' W" I! q9 c @2 |& W
static int posix_thread_init(void)
. `# y$ ^' d, K
{
; e9 m, F. I7 f
int result;
0 [( O- Z. W; P; @% k& B3 Z
result = pthread_create(&tid1, NULL, thread1_entry, NULL);
4 m( h, X0 T! h T
if( result == 0 )
9 t9 O! N8 c2 M( S g
{
9 u0 R% Q8 Q- Q6 A2 w6 [
printf("pthread_create success\n");
1 L- u6 z4 o: N
}
+ ~/ N; d; a# I6 P% b* y
else
3 `: m+ N# [+ z) F7 j
{
3 k/ N/ Z1 Q( Z. f
printf("pthread_create fail\n");
5 U0 W K4 z7 w( x
}
6 Z2 W! g B ]2 v( t! |6 F
pthread_join(tid1, NULL);
+ Q$ G% ]/ c B5 d9 }+ }! ^9 o
printf("posix_thread_init exit\n");
4 D+ D+ U. @: h. d
return 0;
5 P6 [. |: |4 T5 i, g
}
9 C% Z9 P- H: y4 c* @/ L6 w; u/ G
INIT_APP_EXPORT(posix_thread_init);
+ b) ~/ M6 }; H1 X- P' R. d% t8 j1 D7 M
作者:
opipo
时间:
2022-9-20 13:12
只有这些代码?根据变量 small_mem 是在哪里定义的?
- G3 I; ~# M$ w9 m. h& j" y
作者:
lahhse
时间:
2022-9-20 14:59
我把你的代码在我的开发板上试了一下,芯片是STM32F型号,把INIT_APP_EXPORT(posix_thread_init);103xx变成了MSH_CMD_EXPORT(posix_thread_init, posix_thread_init);方便进行测试,连续测试了多次结果没有出现你的上述问题,我的内核版本是4.0.4,使用的工作室进行的开发,,不知道你的开发板芯片型号是什么?
/ Y+ L( _& a0 @; i( O: Q# j8 p
作者:
Blah
时间:
2022-9-20 15:23
换个开发版试试
& w$ o5 U3 I; p! i
欢迎光临 EDA365电子论坛网 (https://bbs.eda365.com/)
Powered by Discuz! X3.2