嵌入式技术论坛
直播中

贾熹

7年用户 1603经验值
私信 关注
[问答]

RT-Thread僵尸线程一直占用资源怎么销毁呢

1.jpg

rt-thread 僵尸线程怎么 销毁,一直占用资源

thread_play = rt_thread_create(“wav_play”,thread_wavplay, argv[1],2048, 2, 25);
/ 启 动 线 程 /
if (thread_play != RT_NULL) rt_thread_startup(thread_play);

void thread_wavplay(void parameter)
{
int fd = -1;
uint8_t buffer = NULL;
struct wav_info *info = NULL;
struct rt_audio_caps caps = {0};

//fd = open("/sd/sine.wav ", O_RDONLY);
fd = open( (const char )( parameter ), O_RDONLY);
if (fd < 0)
{
rt_kprintf("open file failed!\n");
goto __exit;
}
buffer = rt_malloc(BUFSZ);
if (buffer == RT_NULL)
goto __exit;
info = (struct wav_info ) rt_malloc(sizeof * info);
if (info == RT_NULL)
goto __exit;
if (read(fd, &(info->header), sizeof(struct RIFF_HEADER_DEF)) <= 0)
goto __exit;
if (read(fd, &(info->fmt_block), sizeof(struct FMT_BLOCK_DEF)) <= 0)
goto __exit;
if (read(fd, &(info->data_block), sizeof(struct DATA_BLOCK_DEF)) <= 0)
goto __exit;
rt_kprintf("wav information:\n");
rt_kprintf("samplerate %d\n", info->fmt_block.wav_format.SamplesPerSec);
rt_kprintf("channel %d\n", info->fmt_block.wav_format.Channels);
/
根据设备名称查找 Audio 设备,获取设备句柄 /
snd_dev = rt_device_find(SOUND_DEVICE_NAME);
/
以只写方式打开 Audio 播放设备 /
rt_device_open(snd_dev, RT_DEVICE_OFLAG_WRONLY);
/
设置采样率、通道、采样位数等音频参数信息 /
caps.main_type = AUDIO_TYPE_OUTPUT; /
输出类型(播放设备 )
/
caps.sub_type = AUDIO_DSP_PARAM; /* 设置所有音频参数信息 /
caps.udata.config.samplerate = info->fmt_block.wav_format.SamplesPerSec; /
采样率 /
caps.udata.config.channels = info->fmt_block.wav_format.Channels; /
采样通道 /
caps.udata.config.samplebits = 16; /
采样位数 */
rt_device_control(snd_dev, AUDIO_CTL_CONFIGURE, &caps);
while (1)
{
int length;
int i;
uint16_t *p_buff; //wav 音频数据有符号
//int16_t p_buff;
/
从文件系统读取 wav 文件的音频数据 */
length = read(fd, buffer, BUFSZ);
p_buff = (uint16_t )buffer;
if (length <= 0)
break;
/
向 Audio 设备写入音频数据 /
rt_device_write(snd_dev, 0, buffer, length);
}
/
关闭 Audio 设备 */
rt_device_close(snd_dev);
__exit:

if (fd >= 0)
close(fd);
if (buffer)
rt_free(buffer);
if (info)
rt_free(info);
return ;
}

sys workq 23 ready
tidle0 31 ready
这2个线程 一直都是 就绪状态, tidle0 应该是一直没执行, sys workq 没用到这个线程

1.jpg

回帖(2)

王辉

2022-8-23 14:40:33
线程不是退出之后会由空闲线程自动销毁么?
举报

王辉

2022-8-23 14:40:40
动态线程的创建和删除调用的接口是rt_thread_create()和rt_thread_delete();静态线程的初始化与脱离调用的接口是rt_thread_init()和rt_thread_detach()。需要注意的是,由于能执行完毕的现场会被系统自动删除,所以不推荐用户使用删除/脱离线程接口。
你检查看下wav_play线程里是不是调用了特殊的接口。
举报

更多回帖

发帖
×
20
完善资料,
赚取积分