Sorry to disturb the thread with many messages. I feel I have to provide
details to my question

In POSIX programming, calling errno is thread-safe in the following sense

1. Thread A makes some system call X, and the call fails
2. Meanwhile, Thread B makes some system call Y. This call also fails
3. Thread A checks its errno. The errno indicates the reason of failure of
call X
4. Thread B also checks its errno. The errno indicates the failure of call Y

The above is guaranteed, because errno is stored in thread-local storage

But Rust uses green thread, which means it's possible that multiple tasks
may run on a thread.

1. Task A calls function core::os::X. The system call fails and sets errno
2. Meanwhile (on the same thread) Task B is switched in and calls
core::os::Y. The system call fails and replaces the errno set from task A.
3. Task A is switched in again, and checks errno. It expects errno returns
the reason of failure of core::os::X, but what A sees is the failure of
core::os::Y

Is above case possible in Rust? If not, how does Rust prevents this?


2013/5/21 김현강 <[email protected]>

> Thank you for the info, but I'm not sure it's what I was looking for.
>
> giterr_last uses pthread_key_create which does knows nothing about rust
> runtime or rust task. How can I use task local storage to safely call
> giterr_last, which uses pthread local storage?
>
> Maybe I'm asking a wrong question. If then, please tell me what I'm wrong
> about.
> --
> Sent from Mailbox <https://bit.ly/SZvoJe> for iPhone
>
>
> On Tue, May 21, 2013 at 9:53 PM, Corey Richardson <[email protected]>wrote:
>
>> On Tue, May 21, 2013 at 8:03 AM, Lucian Branescu
>> <[email protected]> wrote:
>> > Rust has task-local storage, which sounds like what you're looking for.
>> This
>> > example (http://bubblingbeebles.livejournal.com/111016.html) is a bit
>> old,
>> > I'm not sure it would still work.
>> >
>> >
>> > On 21 May 2013 09:16, Kim HyunKang <[email protected]> wrote:
>> >>
>> >> Hello list.
>> >>
>> >> I'm a Rust newbie and I'm really excited about this language
>> >>
>> >> As a process of knowing each other, I'm implementing a libgit2
>> bindings
>> >> for Rust. (You can look at the code at here:
>> >> https://github.com/kimhyunkang/git2-rs though it has virtually no
>> features
>> >> for now.)
>> >>
>> >> libgit2 uses thread local storage to store and retrieve error info
>> from
>> >> last library call. But the Rust tutorial states that tasks are
>> considered
>> >> green threads. As far as I can understand, that means tasks are not
>> mapped
>> >> 1:1 to OS thread, thus making thread-local storage unsafe for direct
>> use.
>> >>
>> >> Then I rememberd errno, another thread local storage that I know of,
>> and
>> >> checked the source code to find out how core::os handles errno. But
>> >> core::os::errno seems to just call __errno without locking or blocking
>> >> anything.
>> >>
>> >> So, the question is:
>> >>
>> >> How does the runtime makes sure that errno is not overwritten by
>> another
>> >> syscall failure? Is it safe to ignore the possibility of another task
>> >> scheduled into the same OS thread?
>> >>
>> >> - kimhyunkang
>>
>> It's http://static.rust-lang.org/doc/core/local_data.html now.
>>
>
>
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to