This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Problem of newlib running on the SMP platform.


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]