You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Henrique Mendonça (JIRA)" <ji...@apache.org> on 2014/02/25 12:05:19 UTC

[jira] [Commented] (THRIFT-2379) Memmory leaking while using multithreading in C++ server.

    [ https://issues.apache.org/jira/browse/THRIFT-2379?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13911469#comment-13911469 ] 

Henrique Mendonça commented on THRIFT-2379:
-------------------------------------------

Hi Nikita,

your manage() function is not thread safe, so your program is likely to crash under a stress test on a non-debug version.
If you have two threads responding it "simultaneously" you are likely to get to following situation:
{code}
printf("reload\n"); //first thread
printf("reload\n"); //second thread
delete[] this->data; //OK
delete[] this->data; //undefined behavior (probably ok during debug, depending on the compiler)
this->loadRes(); //new
this->loadRes(); //overwrite last new (which won't be deleted!)
{code}

You can solve this with smart pointers (e.g. boost/std shared pointer) but you still need to be very careful with other not thread safe methods/classes!
I hope it helps.

- Henrique

> Memmory leaking while using multithreading in C++ server.
> ---------------------------------------------------------
>
>                 Key: THRIFT-2379
>                 URL: https://issues.apache.org/jira/browse/THRIFT-2379
>             Project: Thrift
>          Issue Type: Question
>          Components: C++ - Library
>    Affects Versions: 0.9.1
>         Environment: Linux Ubuntu 12.10 x64
>            Reporter: Nikita Vdovushkin
>              Labels: performance
>
> I have a problem, with memory leakin in apache thrift, I tried to ask at IRC yesterday, but that didn't help.
> I'm using Apache Thrift framework, I'm writing a application, that has server on C++ and python client. The application has big resources object, that are using during the life. My application need to have a reload method, that should delete all resources, and load new instances from the disk. I wrote the cleannig method, and calling it before reload method. That's work, if I use TSimpleServer. But when I'm starting to use ThreadedServer or TNonBlocking server. Cleannig method doesn't work, as I can see, It's calling but it doesn't cleans . Server just starting to use twice amount of memmory. I tried to use a mutex during cleaning method, but that didn't help.
> I think th matter is multithreading, other method doesn't allow to release old resources, but I'm not shure.
> I wrote example code that has the same issue, and it's quite clear for understaing, I think.
> Code example:
> http://pastebin.com/qW8Ab1xQ
> Full code availble in zip archive:
> https://docs.google.com/file/d/0B73BxCSXgnuzbXlncllSU0NDQkE/edit



--
This message was sent by Atlassian JIRA
(v6.1.5#6160)