找回密码
 注册
关于网站域名变更的通知
查看: 269|回复: 3
打印 上一主题 下一主题

调用pthread_join以后报错有大佬知道怎么解决吗

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2022-9-20 11:18 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

该用户从未签到

2#
发表于 2022-9-20 13:12 | 只看该作者
只有这些代码?根据变量 small_mem 是在哪里定义的?
% w  a) C( v! @  W* D" K

该用户从未签到

3#
发表于 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,使用的工作室进行的开发,,不知道你的开发板芯片型号是什么?
" [2 x1 m* V3 [: V6 O2 k: _& y* p1 g
  • TA的每日心情
    开心
    2023-6-2 15:15
  • 签到天数: 1 天

    [LV.1]初来乍到

    4#
    发表于 2022-9-20 15:23 | 只看该作者
    换个开发版试试  a, Y6 w) b& }$ m
    您需要登录后才可以回帖 登录 | 注册

    本版积分规则

    关闭

    推荐内容上一条 /1 下一条

    EDA365公众号

    关于我们|手机版|EDA365电子论坛网 ( 粤ICP备18020198号-1 )

    GMT+8, 2025-11-23 17:23 , Processed in 0.171875 second(s), 24 queries , Gzip On.

    深圳市墨知创新科技有限公司

    地址:深圳市南山区科技生态园2栋A座805 电话:19926409050

    快速回复 返回顶部 返回列表