Problem of newlib running on the SMP platform.

Hao Shen william.shen@gmail.com
Thu Jan 11 20:49:00 GMT 2007


Thanks a lot.
Should I modify the source file libc/include/sys/config.h directly? Or
it's possible for me to add something during the configure time?

By assigning every thread a _reent struct, can I avoid that two
threads access the printf function at the same time? And can I avoid
to get terrible output on the screen?


On 1/11/07, Jeff Johnston <jjohnstn@redhat.com> wrote:
> Hao Shen wrote:
> > Hi, everybody,
> >
> > I have found a problem about newlib running on the SMP platform.
> > First I describe my design environment here.
> > 1. SMP platform shares the same memory and used the same memory address.
> > 2. We have our SMP operating system which provide multi-thread and locks.
> > 3. In the simulation, I found that the two threads in two different
> > CPUs enter the same system call at the same time. For example, both
> > threads call the "printf" and the output is terrible.
> >
> > I have read some mails of newlib before. People suggest use
> > _impure_ptr and _reent. For my situation should I
> > 1. Use two different _reent for two CPUs?
> > 2. Use a different _reent for each thread?
> > 3. Use only one _reent in whole system and lock it to guarantee only
> > one thread is using system call at the same time.
> >
> > I am waiting for the answers.
> >
>
> Number 2.  Each thread should have its own __reent struct.  If you set
> the magic flag: __DYNAMIC_REENT__ in libc/include/sys/config.h for your
> platform/OS, then the default _REENT macro gets mapped to be a function
> call to __get_reent() (e.g. i386 linux sets this flag on).  You need to
> provide the __getreent() function which returns a _reent struct for the
> current thread.  How you do the mapping is up to you (e.g. you could use
> a thread local storage area).
>
> -- Jeff J.
>


-- 
Hao Shen



More information about the Newlib mailing list