threads on Solaris 2.3: do they work?

Steve Kirsch (stk@infoseek.com)
Sun, 27 Feb 1994 17:45:34 +0800

Has anyone tried threads on Solaris 2.3?

I'm running on a SparcCenter 1000 with 4 CPUs.

I constructed a little function that should take 2 seconds to finish.
With 7 threads running simultaneously, I expected it to take less than
4 seconds of real time (since I have 4 CPUs). This is what I got with
fork. Worst case, if it didn't use the multi-tasking, should be 14
seconds. It actually took 76 seconds of cpu time for all the threads
to finish!!!

Note the high number of context swithes in the vmstat listing: over
10,000 per second!! (for the fork version of this, the number of
context switches remains very low). Is this the problem? Is there
anyway to change this? The program follows below.

Am I doing something wrong, is python doing something wrong, or do
LWPs not work worth beans on Solaris??

I tried creating separate functions for each thread, (in case there
were contention problems with accessing the function definition) but
that didn't seem to change the numbers much.

============================
Python 1.0.1 (Feb 21 1994)
Copyright 1991-1994 Stichting Mathematisch Centrum, Amsterdam
>>> ## working on region in file /usr/tmp/pythona001rT ...
(0.48, 0.21, 0.0, 0.0)
procs memory page disk faults cpu
r b w swap free re mf pi po fr de sr s0 s2 s2 s2 in sy cs us sy id
0 0 0 36420 102544 0 4 1 0 0 0 0 0 0 1 1 38 125 76 0 2 98
3 0 0 353344 88152 0 11 0 0 0 0 0 0 0 0 0 286 12801 10150 32 55 13
1 0 0 353344 88152 0 0 0 0 0 0 0 0 0 0 0 138 12091 10705 30 56 14
3 0 0 353344 88152 0 0 0 0 0 0 0 0 0 0 0 120 12289 10548 34 49 16
3 0 0 353344 88152 0 0 0 0 0 0 0 0 0 0 0 125 12646 10350 26 61 13
0 0 0 353344 88152 0 0 0 0 0 0 0 0 0 0 0 123 12253 10671 31 54 14
2 0 0 353344 88152 0 0 0 0 0 0 0 0 0 0 1 133 11991 10458 33 51 16
1 0 0 353344 88152 0 0 0 0 0 0 0 0 0 0 0 137 12567 10408 30 56 14
.....etc..... etc.....
1 0 0 353344 88148 0 0 0 0 0 0 0 0 0 0 0 145 12504 10624 31 56 14
2 0 0 353344 88148 0 0 0 0 0 0 0 0 0 0 0 141 10913 9500 25 53 22
2 0 0 353344 88148 0 0 0 0 0 0 0 0 0 0 0 124 12211 10218 29 55 16
thread 1 done: (73.83, 131.94, 0.0, 0.0)
3 0 0 353344 88148 0 1 0 0 0 0 0 0 0 0 0 183 12699 10236 33 48 18
thread 6 done: (74.21, 132.76, 0.0, 0.0)
2 0 0 353336 88140 0 1 0 0 0 0 0 0 0 0 0 185 11284 10225 24 50 26
0 0 0 353336 88136 0 1 0 0 0 0 0 0 0 0 0 129 10530 10498 24 46 30
thread 5 done: (76.07, 136.45, 0.0, 0.0)
thread 4 done: (76.48, 137.19, 0.0, 0.0)
thread 7 done: (76.67, 137.43, 0.0, 0.0)
thread 3 done: (76.67, 137.43, 0.0, 0.0)
1 0 0 353332 88132 0 4 0 0 0 0 0 0 0 0 0 328 8723 8349 21 39 40
thread 2 done: (76.99, 137.43, 0.0, 0.0)
0 0 0 353316 88116 0 1 0 0 0 0 0 0 0 0 0 240 97 53 8 0 92
0 0 0 353316 88116 0 0 0 0 0 0 0 0 0 0 0 90 40 24 0 0 100

===============================================================
# thread test

import thread
import posix # for posix.times()
import os # for system

def bar(num):
i=0
while i<130000:
i=i+1
print 'thread', num, 'done:', posix.times()
thread.exit_thread()

i=1
while i<=7:
thread.start_new_thread(bar,(i,))
i=i+1

print posix.times()
os.system('vmstat 1')