2009-05-14 03:30:38     the performance of multi-threaded programing in trunk-svn

Document created by Aaronwu Employee on Aug 15, 2013
Version 1Show Document
  • View in full screen mode

2009-05-14 03:30:38     the performance of multi-threaded programing in trunk-svn

Nicole Otsuka (CHINA)

Message: 74029   

 

hello,i met a problem in multi-threaded programing compiled in uclinux-trunk-svn

 

here is my code: (it can play MP3 by a static MPLAYER library)

 

//==========================start=of=file========================

 

#include <string.h>

#include <stdio.h>

#include <pthread.h>

#include <limits.h>

 

pthread_t Mp3PlayThreadHandle0;

pthread_t Mp3PlayThreadHandle1;

pthread_t Mp3PlayThreadHandle2;

pthread_t Mp3PlayThreadHandle3;

pthread_t Mp3PlayThreadHandle4;

pthread_attr_t thread_attr;

 

 

char* mplayer_argv[] =

{

    "mplayer",

    "/iicore/gadget/musics/planetarium.mp3",

    "-msglevel", "all=-1",

    "-loop", "0",

};

 

void play_music_worker()

{

    mplayer_main(sizeof(mplayer_argv) / sizeof(mplayer_argv[0]), mplayer_argv);

}

 

void* Mp3PlayThreadRoutine0(void* ptr){

    while (1) {

        play_music_worker();

    }

}

void* Mp3PlayThreadRoutine1(void* ptr){

    while (1) {

        sleep(1);

    }

}

void* Mp3PlayThreadRoutine2(void* ptr){

    while (1) {

        sleep(1);

    }

}

void* Mp3PlayThreadRoutine3(void* ptr){

    while (1) {

        sleep(1);

    }

}

void* Mp3PlayThreadRoutine4(void* ptr){

    while (1) {

        sleep(1);

    }

}

 

int main(){

int res,status;

size_t stack_size;

    pthread_attr_init (&thread_attr);

    status = pthread_attr_setstacksize (&thread_attr, 1024*64);

    res = pthread_create(&Mp3PlayThreadHandle0,

                    &thread_attr,

                    Mp3PlayThreadRoutine0,

                    NULL);

    res = pthread_create(&Mp3PlayThreadHandle1,

                    NULL,

                    Mp3PlayThreadRoutine1,

                    NULL);

    res = pthread_create(&Mp3PlayThreadHandle2,

                    NULL,

                    Mp3PlayThreadRoutine2,

                    NULL);

    res = pthread_create(&Mp3PlayThreadHandle3,

                    NULL,

                    Mp3PlayThreadRoutine1,

                    NULL);

    res = pthread_create(&Mp3PlayThreadHandle4,

                    NULL,

                    Mp3PlayThreadRoutine2,

                    NULL);

    while(1) {

        sleep(1);

    }

}

 

//==========================end=of=file========================

 

 

 

when i only created Mp3PlayThreadHandle0, its percent of usage of CPU(%CPU) is 17%.

 

BUT if i also created Mp3PlayThreadHandle1 &2 &3 &4 like the code above, %CPU became 60%

 

AND i remember that %CPU was about 17% when i ran the same program compiled in uClinux-2008R1.5 last week

 

 

 

does the new version of libpthread have some problem?or should i change my code to another way?

 

help me, thank you very much

 

 

 

nicole

QuoteReplyEditDelete

 

 

2009-05-14 03:35:09     Re: the performance of multi-threaded programing in trunk-svn

Mike Frysinger (UNITED STATES)

Message: 74030   

 

you're saying that 1 decode thread takes 17% but 4 takes 60% and you think that's wrong ?  sounds like it's correct to me.

QuoteReplyEditDelete

 

 

2009-05-14 04:06:08     Re: the performance of multi-threaded programing in trunk-svn

Nicole Otsuka (CHINA)

Message: 74031   

 

hi,mike

 

thank you for your reply.

 

but the thread1-4 are sleeping.they are not doing decoding like thread0

 

 

 

i found the %CPU was affected by my another running program ...i may not test it totally

 

i will do some testing and if there is also some problem,i will continue this thread

 

thank you

Attachments

    Outcomes