| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Os/2 bckgrnd program |
What no native OS2 program? :-) Are you sure that you have background
execution on? Compile this little skeleton program which should give you a
visual view of what is happening. When executed the right way, SLEEPER ON,
it should only use 1 or 2 percent of your CPU. Fire up half a dozen
copies, (START /WIN SLEEPER ON); highlight them in the tasklist and tile
the windows. Do other things with your system and you should find them all
still running. Replace one of the dummy functions with your clock check
and file I/O. When it is all working then port it back to your original
program.
/* Sleeper.c a gee wiz test by Lynn Nash */ #include
#include #include #include
#define BOOL(x) (!(!(x))) void (*kbloop1)(void) = NULL; /* generic
function pointer */ void (*kbloop2)(short *) = NULL; /* generic function
pointer */ short count = 0; /* counter variable */
void sleeper(void) {
union REGS regs; /* temporary DOS interrupt register */
regs.x.ax = 0x1680; /* time slice release flag */
int86(0x2f, ®s, ®s); /* give up remainder of timeslice */ }
short looper(short itoggle) { /* a typical DOS stealth polling loop */
short i;
for (;;) {
if (kbhit()) {
i = getch();
if (i)
return i; /* a regular key */
else
return (short) (getch() + 256); /* a function key */
}
if (kbloop1 != NULL) /* pointer to spin function 1 */
(*kbloop1)();
if (!itoggle)
sleeper(); /* return to OS2 */
if (kbloop2 != NULL) /* pointer to spin function 2 */
(*kbloop2)(&count);
if (!itoggle)
sleeper(); /* return to OS2 */
}
}
void DoNothing1(void) {
fprintf(stdout, "Count is now %d +0+\r", count++); }
void DoNothing2(short *acount) {
fprintf(stdout,"Count is now %d *o*\r", (*acount)--); }
#define HLP_MSG \
"\nThis routine tests the OS/2 time slice release function.\n" \
"Usage: SLEEPER OFF\n" \ "Will run the routine saturating
the time slice\n" \ "Usage: SLEEPER ON\n" \ "Will run
the routine releasing each time slice\n" \ "Enjoy --Lynn \n"
int main(int argc, char *argv[]) {
if (argc < 2) {
fprintf(stdout, "%s", HLP_MSG);
return -1;
}
if ((stricmp("ON", argv[1]) != 0) &&
(stricmp("OFF", argv[1]) != 0)) {
fprintf(stdout, "%s", HLP_MSG);
return -1;
}
kbloop1 = DoNothing1; /* Attach a function to spinner */
kbloop2 = DoNothing2; /* Attach a function to spinner */
fprintf(stdout, "\n");
/* Go spin around until a keypress */
return looper(BOOL(stricmp("ON", argv[1]))); }
/*-------------------------End of Line-------------------------------*/
--Lynn
* SLMR 2.1a * W.A.R.P.: We Appreciate Real Programming
--- DB 1.39/004485
* Origin: The Diamond Bar BBS, San Dimas CA, 909-599-2088 (1:218/1001)SEEN-BY: 50/99 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 @PATH: 218/1001 3615/50 396/1 270/101 712/515 711/808 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™.