develooper Front page | perl.ithreads | Postings from June 2008

Re: Memory usage

Thread Previous
From:
Javier Terceiro
Date:
June 11, 2008 07:59
Subject:
Re: Memory usage
Message ID:
602eb19e0806110758l25f78b4w3d9f7605727e2e6f@mail.gmail.com
2008/6/11 Jerry D. Hedden <jdhedden@cpan.org>:
> On Wed, Jun 11, 2008 at 9:26 AM, Javier Terceiro <correolista@gmail.com> wrote:
>> Hello list,
>>
>> I am designed a new software. I am using threads. The operation is
>> correct, but memory consumption is excessive. The system is using 100
>> MB and when the software is working, 500 Mb. The memory is not
>> released, why?
>
> You need to either join the threads after they're done working, or
> else detach them.  See below.
>
>>
>> The source code is:
>>
>> -----------------------------------------------------------------------------
>>
>> #!/usr/bin/perl -w
>>
>> use strict;
>> use warnings;
>> use AnyData;
>> use Sys::Syslog;
>> use Sys::Syslog qw(:DEFAULT setlogsock);
>> use Sys::Syslog qw(:standard :macros);
>> use POSIX qw(setsid);
>> use threads;
>> use threads::shared;
>>
>> sub mail
>> {
>>        print ("The mail thread\n");
>>        return 0;
>> }
>>
>> sub mf
>> {
>>        print ("The mf thread\n");
>>        return 0;
>> }
>>
>> sub scan_files
>> {
>>        while(1)
>>        {
>>                foreach (readdir(DIRHANDLE))
>>                {
>>                        if (!-d $_)
>>                        {
>>                                my $opt =
>> choose_file_option("workq/",$_,"Delivered");
>>                                switch ($opt)
>>                                {
>>                                        case "mail"
>>                                        {
>>                                                threads->new(\&mail, $_);
>
> threads->new(\&main, $_)->detach();
>
>>                                        }
>>                                        case "mf"
>>                                        {
>>                                                threads->new(\&mf, $_);
>
> threads->new(\&mf, $_)->detach();
>
>>                                        }
>>                                        else
>>                                        {
>>                                                syslog ('daemon|info',
>> "Send mail. Failure detected");
>>                                        }
>>                                }
>>                        }
>>                }
>>                sleep(60);
>>        }
>> }
>>
>> sub daemon
>> {
>>        chdir "/";
>>        open STDIN, '/dev/null';
>>        open STDOUT, '>/dev/null';
>>        open STDERR, '>/dev/null';
>>        fork && exit;
>>        setsid();
>>        if (open PID, '>', '/var/run/program.pid')
>>        {
>>                print PID "$$\n";
>>                close PID;
>>        }
>> }
>>
>> setlogmask( LOG_MASK($Fax::Config::param{'log_info'}) );
>> openlog 'faxqr', 'pid', LOG_DAEMON;
>> daemon();
>>
>> $SIG{"TERM"} = \&notify_exit;
>>
>> scan_files();
>>
>> -----------------------------------------------------------------------------
>>
>> Any idea that there is a very high consumption of memory.
>>
>> --
>> A greeting,
>>
>> Javier.
>>
>

Hi,

I aply this changes, but now I obtein a fatal error:

*** glibc detected *** double free or corruption (!prev): 0x08fea490 ***

And the process is cancel :(

Any idea?

-- 
A greeting,

Javier.

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About