| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | newby - mutex semaphores |
/* On 12/14/95 at 09:09AM, Phil Crown blathered to Paul Haggart */
> btw, I thought I saved the code, but I can't find it. Would you please
> repost it?
Peter Fitzsimmons gave me a few corrections.. when I changed it to his
code, I didn't bother keeping the older stuff. Here's what he gave me:
=== Cut - client.c ===
/* client.c - mutex semaphore test */
#define INCL_DOSSEMAPHORES
#define INCL_DOSPROCESS
#include
#include
#include
int main(void)
{
HMTX semHandle = NULLHANDLE;
USHORT count;
APIRET rc;
/* open semaphore */
if(rc = DosOpenMutexSem("\\SEM32\\SEMAPHOR.SEM", &semHandle))
{
printf("Error #%u opening semaphore '\\SEM32\\SEMAPHOR.SEM'\n"
"Make sure SERVER.EXE is running!\n", rc);
return 0;
}
for (count = 0; count < 10000; count++)
{
/* check to see if the semaphore is blocked from the server */
if (rc = DosRequestMutexSem(semHandle, -1))
{
printf("DosRequestMutexSem returned error #%u\n", rc);
return 1;
}
/* print useless counter message */
printf("%u\n", count);
/* release semaphore to the open */
DosReleaseMutexSem(semHandle);
/* release a timeslice - increase number for more delay */
DosSleep(5L);
}
return 0;
}
=== Cut ===
=== Cut - server.c ===
/* server.c - mutex semaphore test */
#define INCL_DOSSEMAPHORES
#define INCL_DOSPROCESS
#include
#include
#include
int main(void)
{
HMTX semHandle = NULLHANDLE;
char ch;
APIRET rc;
/* create the public semaphore */
if (rc = DosCreateMutexSem("\\SEM32\\SEMAPHOR.SEM", &semHandle,
(ULONG)0, (BOOL32)0))
{
printf("DosCreateMutexSem returned error #%u\n", rc);
return 1;
}
printf("Semaphore \\SEM32\\SEMAPHOR.SEM created successfully!\n"
"Hit any key to pause client..\n\n");
for (;;)
{
/* wait for keypress to pause client */
ch = getch();
/* grab semaphore from client */
if(rc = DosRequestMutexSem(semHandle, -1))
{
printf("DosRequestMutexSem returned error #%u\n", rc);
return 1;
}
printf("Output in client window should be paused\n");
/* wait for keypress to start client again... */
getch();
printf("Output in client window should be running again\n");
/* release semaphore to client */
DosReleaseMutexSem(semHandle);
}
}
=== Cut ===
// Paul - A proud member of Team OS/2 - phaggart{at}f306.n248.z1.fidonet.org
... "I wonder if it tastes like chicken?" sayeth the Lord.
---
* Origin: TOTSE/2 - mail nexus extraordinaire! (1:248/306)SEEN-BY: 270/101 620/243 711/401 409 410 413 430 808 809 934 955 712/407 515 SEEN-BY: 712/517 628 713/888 800/1 7877/2809 @PATH: 248/306 303 1 3615/50 396/1 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™.