Re: C++ exceptions with many threads and no memory.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 04/03/14 17:05, Ian Lance Taylor wrote:
> On Mon, Mar 3, 2014 at 3:53 AM, John Steele Scott <toojays@xxxxxxxxxxx> wrote:
>>
>> When comparing this to GCC's exception handling, I find that libstdc++ calls malloc() whenever an exception is thrown, and falls back to statically allocated memory only when malloc fails. Only 64 statically allocated exceptions may be in flight at once, and if this limit is violated, std::terminate() is called.
>>
>> This seems like quite a brittle behaviour to me. I guess not often seen as a problem in practice because Linux overcommit usually ensures malloc() won't fail (although if it does, then you have to take your chances with the oom-killer anyway).
>>
>> There doesn't seem to be any way around this, is there? Do GCC developers consider it a bug?
> 
> If you have a good proposal for how to handle this situation, I'm sure
> that GCC developers would consider it.
> 
> It seems pretty tough to handle large numbers of exceptions when
> malloc fails.  And since it is such an unusual condition, I don't
> think it would be a good idea to address it in a manner that penalizes
> performance in ordinary conditions.

Thanks Ian for your reply.

I agree, it's tough to find a suitable general solution which scales with the
number of threads, and I don't have a solution for the general case. In my case,
we have a thread budget, it's just that the number of threads we use is much
larger than the 64 which GCC can guarantee to safely handle.

I'd settle for being able to supply my own pair of allocation/deallocation
functions for this specific use case, and having enough documentation to be able
to confidently estimate the amount (size and shape, i.e. N blocks of M bytes
each) of memory I'd need to reserve for this.

>From what I've seen so far, it seems that as long as I know the maximum number
of threads in my program, and the maximum size of the exceptions in my program,
this should be doable, if I could override the memory allocator just for
__cxa_allocate_exception() and friends.

I admit to not having a deep understanding of GCC/libstdc++ implementation
details or C++ exceptions. If there are other reasons as to why this wouldn't
work, I'd appreciate knowing about them.

Cheers,

John




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux