Pthreads: Solaris 2.6 aren't multithreading

Pthreads: Solaris 2.6 aren't multithreading

Post by Chan Shih-Pin » Mon, 13 Jul 1998 04:00:00



Problem: A pthreaded programme is running the threads
sequentially not concurrently.

I'm running code like the following on Solaris 2.6
(The code runs correctly and multithreads on Digital Unix 4.0d
and Linux on both SMP and UP machines.) It does *NOT*
run concurrent threads on Solaris 2.6.

pthread_attr_init(...)
pthread_attr_setinheritsched(...) /* set to EXPLICIT */
pthread_attr_setschedpolicy(...) /* set to SCHED_OTHER */

pthread_create(....)
pthread_create(....)

pthread_exit(...)

Each thread creates a file and does work so that I can tell
if the threads are running concurrently or sequentially. But
the threads are not running concurrently. Instead the first
thread completes before the second starts. Is there something I should
check?? Machine is Ultra 450 with two CPUs. BTW why does libc.so
have pthread_ symbols - doesn't this mean that -lpthread is unnecessary?

It doesn't seem to make a difference if I use -lpthread or not
on the compilation.

--
Chan Shih-Ping


Tel:    +65 874 3343  | Department of Mathematics
Fax:    +65 779 5452  | 10 Kent Ridge Crescent 119260
    | Singapore

 
 
 

Pthreads: Solaris 2.6 aren't multithreading

Post by Jin-su A » Tue, 14 Jul 1998 04:00:00


: Each thread creates a file and does work so that I can tell
: if the threads are running concurrently or sequentially. But
: the threads are not running concurrently. Instead the first
: thread completes before the second starts. Is there something I should
: check?? Machine is Ultra 450 with two CPUs. BTW why does libc.so
: have pthread_ symbols - doesn't this mean that -lpthread is unnecessary?
:
: It doesn't seem to make a difference if I use -lpthread or not
: on the compilation.
:

Different. The pthread_ symbols in libc.so are simple placeholders for non-
threaded codes. Simply, they are empty.

For your main question, I suggest to try thr_setconcurrency().

        - Ahn

-----

School of Electrical Engineering
Seoul National University, Korea

 
 
 

Pthreads: Solaris 2.6 aren't multithreading

Post by Chan Shih-Pin » Wed, 15 Jul 1998 04:00:00


Tks to net wisdom and the book by Lewis and Berg on Pthreads
it seems that for Solaris you need to set the contention scope to system

pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);

This will create enough LWPs for your threads to run concurrently.

Now my next question would be: how do you create enough LWPs
for threads to run concurrently if the scope is PTHREAD_SCOPE_PROCESS.

Why do other unices behave differently: Digital Unix 4.0D and Linux don't
require
PTHREAD_SCOPE_SYSTEM.


> Problem: A pthreaded programme is running the threads
> sequentially not concurrently.

> I'm running code like the following on Solaris 2.6
> (The code runs correctly and multithreads on Digital Unix 4.0d
> and Linux on both SMP and UP machines.) It does *NOT*
> run concurrent threads on Solaris 2.6.

> pthread_attr_init(...)
> pthread_attr_setinheritsched(...) /* set to EXPLICIT */
> pthread_attr_setschedpolicy(...) /* set to SCHED_OTHER */

> pthread_create(....)
> pthread_create(....)

> pthread_exit(...)

> Each thread creates a file and does work so that I can tell
> if the threads are running concurrently or sequentially. But
> the threads are not running concurrently. Instead the first
> thread completes before the second starts. Is there something I should
> check?? Machine is Ultra 450 with two CPUs. BTW why does libc.so
> have pthread_ symbols - doesn't this mean that -lpthread is unnecessary?

> It doesn't seem to make a difference if I use -lpthread or not
> on the compilation.

> --
> Chan Shih-Ping


> Tel:    +65 874 3343  | Department of Mathematics
> Fax:    +65 779 5452  | 10 Kent Ridge Crescent 119260
>     | Singapore

 
 
 

Pthreads: Solaris 2.6 aren't multithreading

Post by Jin-su A » Wed, 15 Jul 1998 04:00:00


: Tks to net wisdom and the book by Lewis and Berg on Pthreads
: it seems that for Solaris you need to set the contention scope to system
:
: pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
:
: This will create enough LWPs for your threads to run concurrently.
:
: Now my next question would be: how do you create enough LWPs
: for threads to run concurrently if the scope is PTHREAD_SCOPE_PROCESS.
:
: Why do other unices behave differently: Digital Unix 4.0D and Linux don't
: require
: PTHREAD_SCOPE_SYSTEM.
:

....Because Solaris has 2-level thread system. The Solaris kernel supports
threads, but since kernel resources are always precious ones, binding all
user threads to kernel threads is a serious waste if the number of active
threads are small. So Solaris thread library is built on top of kernel
thread and multiplexes user threads to kernel ones. The thread library
makes more kernel threads if necessary and frees some if not in use.

....In Solaris implementation, if you specify PTHREAD_SCOPE_SYSTEM, pthread_
create() gives you a thread permanently bound to a kernel thread. It is
not so lightweight; in my experiments, context changes of kernel threads take
up to 2/3 (huh? it's too large; maybe a fiction; I can't recall the figure
exactly, but they are really heavy) of time needed for those of processes.
User-level threads are lightweight. They exhibit lower latency; typically,
less than 1/10 of kernel ones. You can get user-level threads with
PTHREAD_SCOPE_PROCESS.

....As you have already experienced, with user-level threads you may not be
able to get desired concurrency. Unfortunately, there's nothing to remedy this
problem in pthread library, except PTHREAD_SCOPE_SYSTEM. But you can use
thr_setconcurrency() for the purpose, which has no counterpart in pthread.

        - Ahn

-----

School of Electrical Engineering
Seoul National University, Korea

 
 
 

Pthreads: Solaris 2.6 aren't multithreading

Post by Chan Shih-Pin » Thu, 16 Jul 1998 04:00:00


This does indeed work: by mixing Solaris threads thr_setconcurrency
call with PTHREAD_SCOPE_PROCESS I was able to obtain
concurrent execution of process scope threads. However this
is non-portable. It seems that Digital Unix and Linux time-slice
process scope threads unlike Solaris. Nevertheless its interesting
to note that Lewis and Berg in the Pthreads book seem to strongly
favour PTHREAD_SCOPE_SYSTEM. Maybe because it doesn't lead
to so many surprises!

[..detailed explanation of Solaris process scope thread contention omitted]

> ....As you have already experienced, with user-level threads you may not be
> able to get desired concurrency. Unfortunately, there's nothing to remedy this
> problem in pthread library, except PTHREAD_SCOPE_SYSTEM. But you can use
> thr_setconcurrency() for the purpose, which has no counterpart in pthread.

>         - Ahn

> -----

> School of Electrical Engineering
> Seoul National University, Korea