home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magazyn Exec 3
/
CD_Magazyn_EXEC_nr_3.iso
/
Programy
/
Biblioteki
/
ppclibemu07.lha
/
tests
/
threadtest.c
< prev
next >
Wrap
C/C++ Source or Header
|
1999-12-10
|
1KB
|
62 lines
#include <stdio.h>
#include <exec/types.h>
#include <dos/dos.h>
#include <utility/tagitem.h>
#include <powerup/ppclib/tasks.h>
extern void *PPCCreatePort(struct TagItem *);
extern void PPCDeletePort(void *);
extern void *PPCCreateMessage(void *,ULONG);
extern void PPCDeleteMessage(void *);
extern void *PPCGetMessage(void *);
extern void PPCWaitPort(void *);
extern void *PPCCreateTask(void *,void *,struct TagItem *);
static int threadfunc()
{
int i;
for (i=1; i<=10; i++)
printf("threadfunc: %d\n",i);
return 1;
}
main()
{
struct TagItem ti[4];
void *replyport,*startupmsg,*msg;
ti[0].ti_Tag = TAG_DONE;
if (replyport = PPCCreatePort(ti)) {
if (startupmsg = PPCCreateMessage(replyport,0)) {
ti[0].ti_Tag = PPCTASKTAG_STARTUP_MSG;
ti[0].ti_Data = (ULONG)startupmsg;
ti[1].ti_Tag = PPCTASKTAG_MSGPORT;
ti[1].ti_Data = TRUE;
ti[2].ti_Tag = TAG_DONE;
if (PPCCreateTask(NULL,(void *)threadfunc,ti)) {
printf("Thread started, waiting for finish...\n");
for (;;) {
if (PPCGetMessage(replyport) == startupmsg) {
printf("Thread finished.\n");
break;
}
PPCWaitPort(replyport);
}
}
else
printf("Couldn't create task!\n");
PPCDeleteMessage(startupmsg);
}
else
printf("Coudn't create startup message!\n");
PPCDeletePort(replyport);
}
else
printf("Couldn't create message port!\n");
exit(0);
}