[#61424] [REJECT?] xmalloc/xfree: reduce atomic ops w/ thread-locals — Eric Wong <normalperson@...>

I'm unsure about this. I _hate_ the extra branches this adds;

13 messages 2014/03/12

[ruby-core:61604] Re: [REJECT?] xmalloc/xfree: reduce atomic ops w/ thread-locals

From: SASADA Koichi <ko1@...>
Date: 2014-03-20 04:23:53 UTC
List: ruby-core #61604
(2014/03/16 5:41), Eric Wong wrote:
> SASADA Koichi <[email protected]> wrote:
>> (2014/03/15 17:34), Eric Wong wrote:
>>>>> BTW,
>>>>>
>>>>>>> +    rb_thread_t *th = ruby_thread_from_native();
>>>>>
>>>>> `th' can be NULL because no Ruby threads can call this code.
>>> Did you mean: gsub(/no Ruby/, "non-Ruby") ?
>>
>> Yes.
>>
>>> I should put a FATAL exit there (but not much different than crashing).
>>
>> You shouldn't.  It should pass.  For example, C-method creates another
>> native threads, and they can use ruby_xmalloc().  This is why this is
>> not `rb_xmalloc()' but `ruby_xmalloc()'.
> 
> xmalloc hits FATAL if called from a non-Ruby thread:
> 	http://yhbt.net/xmalloc_from_pthread.diff
> 
> $ ./miniruby -e 'Thread.test_xmalloc 50000000'
> [FATAL] failed to allocate memory
> 
> Should we care to support xmalloc/xfree in non-Ruby native threads?
> I think it's too much work.

We should use `rb_' prefix if we only support for ruby threads.

In fact, I had proposed same issue before.  However, it was rejected.
At this time, I heard that the name of `xmalloc()' is safe malloc().
`Safe' means that this function check NULL checking.

Anyway, current "[FATAL] failed to allocate memory" error in your test
program is bug :(
We shouldn't invoke GC() otherwides return value of malloc() is 0.

-- 
// SASADA Koichi at atdot dot net

In This Thread