Multi-threaded application - Should num of processors equal num of threads?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nagaraj_hayyal
    New Member
    • Nov 2005
    • 2

    Multi-threaded application - Should num of processors equal num of threads?

    Hi All,
    thanks for reading this post.
    just wanted to know about the ratio of threads and processors.
    i am working on c++ on AIX5.2 platform.
    my c++ program are multithreaded programs.


    In a multithreaded application,sho uld no of processors be equal to no of threads ?
    if we set the thread_scope to system( meaning 1 kernel thread to 1
    user thread), does that mean that processors should be equal or more
    than the threads?
    suppose if we set,
    rc = pthread_attr_se tscope(&tattr,P THREAD_SCOPE_SY STEM);


    And if i have 4 processors and 7 threads running simultaneously in my
    applications.
    will that work? or will it cause coredump ? will other threads wait for


    CPU.
    how is the ratio mapped?
    how will the scheduler behave in this case?
    please help me in resolving my issues.
    thanks in advance to all the experts for their opinion.


    Regards
    Nagaraj Hayyal.
  • gnanapoongothai
    New Member
    • Jun 2007
    • 62

    #2
    Originally posted by nagaraj_hayyal
    Hi All,
    thanks for reading this post.
    just wanted to know about the ratio of threads and processors.
    i am working on c++ on AIX5.2 platform.
    my c++ program are multithreaded programs.


    In a multithreaded application,sho uld no of processors be equal to no of threads ?
    if we set the thread_scope to system( meaning 1 kernel thread to 1
    user thread), does that mean that processors should be equal or more
    than the threads?
    suppose if we set,
    rc = pthread_attr_se tscope(&tattr,P THREAD_SCOPE_SY STEM);


    And if i have 4 processors and 7 threads running simultaneously in my
    applications.
    will that work? or will it cause coredump ? will other threads wait for


    CPU.
    how is the ratio mapped?
    how will the scheduler behave in this case?
    please help me in resolving my issues.
    thanks in advance to all the experts for their opinion.


    Regards
    Nagaraj Hayyal.

    it is always no of thread to num of processors bcos creating n threads without processors will end up in race or dead lock. u can have pools of threads but active threads eqaul to the proceesors number only

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Originally posted by gnanapoongothai
      it is always no of thread to num of processors bcos creating n threads without processors will end up in race or dead lock. u can have pools of threads but active threads eqaul to the proceesors number only
      The last part is true, the first part isn't. When there are no processors available
      at any moment in time a thread simply won't run but is scheduled as runnable.
      It has nothing to do with deadlocks or race conditions. Even with a zillion cpus
      and two threads deadlocks can occur.

      kind regards,

      Jos

      Comment

      Working...