problem with thr_create

problem with thr_create

Post by Aaro » Fri, 10 Mar 1995 09:09:10



I am new to threads, so I'm writing a simple test program, and OF COURSE
I'm having a problem with it.  Program follows.

I would appreciate it if anyone could suggest anything, and also point me
toward a good reference.  Thanks very much.

I have a thread for main(), and main does thr_create for two threads, which
I am trying to create as THR_SUSPENDED.

Each thread does thing1, thr_yield(), thing2.

I was expecting to see:
        thread1, thing1
        thread2, thing1
        thread1, thing2
        thread2, thing2

Instead, I see:
        thread1, thing1
        thread1, thing2
        thread2, thing1
        thread2, thing2

It looks like each thread's function is being executed as a straight
function rathere than a thread.  I would have gotten my exact same results
if I had just called the functions directly from my main().

Notice, according to my output (shown after source), that each thread
function thinks its TID is the same as main's TID.  What gives?

And another thing: even though I create the threads THR_SUSPENDED,
they just execute anyway, event though I don't do a thr_continue.

---------------------------------------------------------------
/* Solaris 2.3, Sparc5 */
/* compile line: gcc main.c -lthread */

void * LeftThread()
{
    printf( "\nLeft String 1, TID: %d\n", thr_self() );
    fflush( stdout );

    thr_yield();

    printf( "Left String 2, TID: %d\n", thr_self() );
    fflush( stdout );

Quote:}

void * RightThread()
{
    printf( "\nRight String 1, TID: %d\n", thr_self() );
    fflush( stdout );

    thr_yield();

    printf( "Right String 2, TID: %d\n", thr_self() );
    fflush( stdout );

Quote:}

main()
{
    int leftTid, rightTid;
    int leftArg, rightArg;

    printf( "\nmain: TID: %d\n", thr_self() );
    fflush( stdout );

    thr_create(
        0,              /* stack, 0 = default stack */
        0,              /* stack size, 0 = default size */
        LeftThread(),   /* thread function */
        0,              /* thrd func arg, 0 = ignore */
        THR_SUSPENDED,  /* flags, 0 = default bits */
        &leftTid );         /* created Thread ID, 0 = ignore */

    printf( "\nmain: left TID: %d\n", leftTid );
    fflush( stdout );

    thr_create(
        0,              /* stack, 0 = default stack */
        0,              /* stack size, 0 = default size */
        RightThread(),  /* thread function */
        0,              /* thrd func arg, 0 = ignore */
        THR_SUSPENDED,  /* flags, 0 = default bits */
        &rightTid );            /* created Thread ID, 0 = ignore */

    printf( "\nmain: right TID: %d\n", rightTid );
    fflush( stdout );

Quote:}

---------------------------------------------------------------

and here's the output:
---------------------------------------------------------------
% a.out

main: TID: 1

Left String 1, TID: 1
Left String 2, TID: 1

main: left TID: 4

Right String 1, TID: 1
Right String 2, TID: 1

main: right TID: 5
%
---------------------------------------------------------------

Thanks very much,
Aaron

 
 
 

1. Problem with thr_create

Hi,

  I am using Solaris 2.3 with kernel patch 101318-54 installed and I have
a serious problem with thr_create.  The following call

    status = thr_create(NULL,NULL,blex_worker,(void *)nodsp,0,
                        &thr_blex.threads[nodsp]);

returns -1.  Does anybody know what kind of error it is?  Any help will
be appreciated.

Thanks in advance,
--
````````````````````````````````````````````````````````````````````````````
    /\ Robin Duquette              /\ Logiciels et algorithmes de reseaux


 / \  / \ phone: (514) 652-8239 / \  / \ machine: fractal.ireq.hydro.qc.ca
/___\/___\ fax: (514) 652-8005 /___\/___\
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

2. Boot PROM revision's relevance?

3. Problem with thr_create??

4. How do 6x86 Cyrix chips do under linux?

5. thr_create problem in 2.5?

6. What is mirroring?

7. wrong example in thr_create(3T) man page

8. Natsemi(NetGear 311/312) eth adp and Woody 2.2.20..????

9. fork vs. exec vs thr_create

10. thr_create & THR_DAEMON

11. thr_create with/without THR_NEW_LWP

12. Stack size in thr_create() on PC's with Sol2.4?

13. Hang in fork1() and thr_create()