TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: All
from: Alan Clifford
date: 1996-03-18 22:57:14
subject: Threads

Hello All 

This is my first, tentative effort at an OS/2 program.  I thought I would
look at threads.  The program is at the end of the message.

I was expecting thread 2 to print a few lines then swap to thread 3, print
a few lines and so on.  But it can get stuck in one of the threads for
about 19 seconds.  I also opened another window and ran the program again
and put a text editor into the foreground in another window.  Whilst the
two processes did run, one process could stall for several seconds and, not
only that, when it did get time, it would continue running the same thread
rather than swapping to the other thread.

Further more, on pressing the return key, it would continue to wack through
thread 2 or 3 and could take 23 seconds for the program to end.

I have MAXWAIT set at 2 in config.sys.  There is no value set for TIMESLICE.

The compiler is GCC/EMX09b

I seem to be missing some fundemental concept here?

Alan


#include 
#include 

int Thread2id;  /* Thread 2 ID */
void thread2(void *argp);
int Thread3id;  /* Thread 3 ID */
void thread3(void *argp);
int Thread2ctr = 0, Thread3ctr = 0;

int main()
{
    if (-1 == (Thread2id = _beginthread(thread2, NULL, 0x40000, NULL))) {
        puts("error creating thread 2");
        exit(1);
    }
    if (-1 == (Thread3id = _beginthread(thread3, NULL, 0x40000, NULL))) {
        puts("error creating thread 3");
        exit(1);
    }
    getchar();
    return 0;
}

void thread2(void *argp)
{
    while (1) {
        Thread3ctr = 0;
        printf("\tthread 2, %d\n", Thread2ctr);
        ++Thread2ctr;
    }
}

void thread3(void *argp)
{
    while (1) {
        Thread2ctr = 0;
        printf("\t\tthread 3, %d\n", Thread3ctr);
        ++Thread3ctr;
    }
}

--- FleetStreet 1.14 NR
* Origin: Alan's Point on Donor/2 (alanc{at}donor2.demon.co.uk) (2:440/4.6)
SEEN-BY: 50/99 78/0 270/101 620/243 711/401 409 410 413 430 808 809 934 955
SEEN-BY: 712/407 515 517 628 713/888 800/1 7877/2809
@PATH: 440/4 141/209 270/101 712/515 711/808 809 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.