This is the mail archive of the
ecos-discuss@sourceware.org
mailing list for the eCos project.
Re: sscanf() exception issue of C lib
- From: Xiaochen Zhou <zhouxiaochen at h3c dot com>
- To: Jonathan Larmour <jifl at eCosCentric dot com>
- Cc: eCos discussion <ecos-discuss at ecos dot sourceware dot org>
- Date: Thu, 15 Jan 2009 09:11:12 +0800
- Subject: Re: [ECOS] sscanf() exception issue of C lib
- References: <496C3E08.7050400@h3c.com> <496E2221.8040505@eCosCentric.com>
Jonathan Larmour 写道:
> Xiaochen Zhou wrote:
>
>> I try hard to check my code, but does not work. At last I browse the c
>> lib code, and have some doubts with the
>> language/c/libc/stdio/current/src/common/fflush.cxx
>>
>> // flush all but one stream
>> externC Cyg_ErrNo
>> cyg_libc_stdio_flush_all_but( Cyg_StdioStream *not_this_stream )
>> {
>>
> [snip]
>
>> (1) only initialize the files_flushed[0] , not all elements.
>>
>
> The C standard mandates that any initialiser causes any remaining elements
> to be initialised to 0.
>
>
yeah, right.
>> (2) Cyg_libc_stdio_files::get_file_stream(i) is not safe here. I think
>> it should need Cyg_libc_stdio_files::lock() &
>> Cyg_libc_stdio_files::unlock() to protect.
>>
>> I'm not sure of this, can someone affirm? thanks!
>>
>
> Although I can't remember the details, you have to be careful in this code
> to avoid deadlock. Is there any particular problem scenario you are hitting
> as a result? Has your problem gone away if you add such a lock?
>
> Jifl
>
I write a test thread to call sscanf() again and again in a loop, and in
the same time, I hit the F5 to flush the web pages of my device very
quickly (httpd has higher priority and call stdio lib's fdopen() and
close()). The exception repeated in few minutes. So I'm sure it is a
ecos lib c bug. Add the lock, after several hours testing, the exception
is gone. But it is not the exact evidence. I will add some testing code
to prove it today.
The deadlock is the problem. I'm not familiar with the c lib code, so I
need expert to help. Thanks!
Xiaochen Zhou
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss