From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,33bfa19a80f0a84a,start X-Google-Attributes: gidfee84,public From: trin0008@ermine.ox.ac.uk (Rick Heylen) Subject: Proper multiprocessor multithreading Date: 1997/03/31 Message-ID: <5hp12d$ntc@news.ox.ac.uk>#1/1 X-Deja-AN: 229739030 Organization: Oxford University, England Newsgroups: comp.unix.osf.osf1 The following program is an attempt to demonstrate proper multiprocessor multiprocessing on a multiprocessor Alpha. #include #include pthread_t threads[4]; void *spin(int p){ int i; for(i=0;i<10000000;i++) {if (i % 1000000==0) printf("Bing%d\n",p);fflush(stdout);} } main() { int i; for (i=0;i<4;i++) pthread_create(&threads[i],NULL,spin,i); sleep(1000); } You compile this with -pthread I can't get it to use more than 1 CPU's worth of cpu utilisation as shown by erm0>ps -m -Opsr,pcpu PID PSR %CPU S TTY TIME COMMAND 10472 3 98.1 R pts/14 0:36.86 a.out 3 0.0 I 0:00.02 0 0.0 I 0:00.00 0 0.0 I 0:00.01 3 45.9 R 0:10.82 3 48.1 R 0:10.16 1 2.1 R 0:08.20 2 2.0 R N 0:07.65 However, proper kernel multithreading is possible as I have seen a dxmandel process with a total pcpu over 300% by running four threads over four processors. Why is my program not using all the available processors? Rick -- -- All I could see was the B-side of the disc which had assumed an oval shape with the label on the outside rim. PGP key 512/CA5CADED Differential Cryptanalyst and C/C++, Java Programmer