Category : OS/2 Files
Archive   : EMXLIB8F.ZIP
Filename : BEGINTHR.C

 
Output of file : BEGINTHR.C contained in archive : EMXLIB8F.ZIP
/* beginth.c (emx+gcc) -- Copyright (c) 1992-1993 by Eberhard Mattes */

#include
#include
#include
#include

#define MAX_THREADS 1024

static struct _thread thread_1 =
{
0, /* _th_errno */
NULL, /* _th_arg */
NULL, /* _th_start */
NULL, /* _th_strtok_ptr (must be NULL) */
{0}, /* _th_asctime_buf */
{0}, /* _th_tmpnam_buf */
{0} /* _th_gmtime_buf */
};

struct _thread *_thread_tab[MAX_THREADS+1] = {NULL, &thread_1};


static void start_thread (struct _thread *tp)
{
tp->_th_start (tp->_th_arg);
_endthread();
}


int _beginthread (void (*start)(void *arg), void *stack, unsigned stack_size,
void *arg_list)
{
ULONG rc;
TID tid;
struct _thread *tp;

rc = DosAllocMem ((PPVOID)&tp, sizeof (struct _thread),
PAG_COMMIT|PAG_READ|PAG_WRITE);
if (rc != 0)
{
errno = ENOMEM;
return (-1);
}
tp->_th_start = start;
tp->_th_arg = arg_list;
rc = DosCreateThread (&tid, (PFNTHREAD)start_thread, (ULONG)tp,
3, stack_size);
if (rc != 0)
{
if (rc == ERROR_NOT_ENOUGH_MEMORY)
errno = ENOMEM;
else if (rc == ERROR_MAX_THRDS_REACHED)
errno = EAGAIN;
else
errno = EINVAL;
return (-1);
}
if (tid > MAX_THREADS)
{
DosKillThread (tid);
errno = EAGAIN;
return (-1);
}
if (__newthread (tid) != 0)
{
DosKillThread (tid);
return (-1);
}
_thread_tab[tid] = tp;
rc = DosResumeThread (tid);
if (rc != 0)
{
errno = ESRCH;
return (-1);
}
return (tid);
}


void _endthread (void)
{
struct _thread *tp;
int tid;

tid = _tid ();
tp = _thread ();
if (tp != &thread_1)
DosFreeMem (tp);
_thread_tab[tid] = NULL;
__endthread (tid);
for (;;)
DosExit ((tid == 1 ? EXIT_PROCESS : EXIT_THREAD), 0);
}


  3 Responses to “Category : OS/2 Files
Archive   : EMXLIB8F.ZIP
Filename : BEGINTHR.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/