Connecting Tech Pros Worldwide Forums | Help | Site Map

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

Newbie
 
Join Date: Nov 2005
Posts: 2
#1: Nov 7 '05
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,should 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_setscope(&tattr,PTHREAD_SCOPE_SYSTEM) ;


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.

Member
 
Join Date: Jun 2007
Posts: 62
#2: Aug 17 '07

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


Quote:

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,should 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_setscope(&tattr,PTHREAD_SCOPE_SYSTEM) ;


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
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#3: Aug 17 '07

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


Quote:

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
Reply