>>>>> Matt Welsh writes:

    Matt> I have a simple Java program where 2 threads spin in a tight
    Matt> loop each grabbing the same lock and releasing it. This is
    Matt> on Linux x86 and has been tested using GCJ 2.95.1, Blackdown
    Matt> JDK 1.1.7v3 (native threads), and IBM JDK 1.1.8 (native
    Matt> threads). Note that I am on an SMP system (IBM Netfinity
    Matt> Dual PIII Xeon).

_Dual_ and the 'for (;;) ;' loop are the explanation here:

Looks like most of time the main thread of your C programm is on one
cpu, while the other two threads are on the other.  This means the two
threads don't really contend for the mutex.  Each of the two threads
gets its time-slice, and while one thread is sleeping the other one
unlocks and immediately re-locks the mutex.

If you make sure that the main thread doesn't consume that much CPU
time the contention will be stronger and the C program should show the
same behavior as the Java code.

    Matt> int main(int argc, char **argv) {
    Matt>   int i;

            pthread_t thread;

    Matt>   pthread_key_create (&_Jv_ThreadKey, NULL);

    Matt>   for (i = 0; i < MAX_THREADS; i++) {
    Matt>       struct sched_param param;
    Matt>       pthread_attr_t attr;
    Matt>       struct my_starter *info;

    Matt>       fprintf(stderr,"CREATING THREAD %d\n", i);

    Matt>       info = (struct my_starter *) malloc (sizeof (struct my_starter));
    info-> tnum = i;
    info-> method = my_threadrun;
    info-> name = (char *)malloc(80);
    Matt>       sprintf(info->name,"thread-%d", i);

    Matt>       pthread_create (&thread, &attr, my_start, (void *) info);
    Matt>   }

    Matt>   fprintf(stderr,"main() spinning.\n"); 

            pthread_join(thread, NULL);

    Matt> }


        Juergen

-- 
Juergen Kreileder, Blackdown Java-Linux Porting Team
http://www.blackdown.org/java-linux.html


----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to