* problem about SEMAPHORE at cygwin 1.5.7
@ 2004-03-01 4:33 xuzhd
2004-03-02 11:33 ` Corinna Vinschen
0 siblings, 1 reply; 2+ messages in thread
From: xuzhd @ 2004-03-01 4:33 UTC (permalink / raw)
To: cygwin
[-- Attachment #1: Type: text/plain, Size: 2017 bytes --]
(See attached file: lcctestsem.c)
problem about SEMAPHORE at cygwin 1.5.7
cygwin 1.5.7
cygserver as ipc server
a process has gotten semaphore using SEM_UNDO, when the process aborts, it
should release corresponding semaphore at Linux.But at Cygwin 1.5.7,1.5.4,
1.3.22, I cannot prove it. is it a bug to cygwin ? thank you
the following is my program's result.
Administrator@node1 ~
$ ./a.exe ( the first running)
before Get semaphore exclusively...
semval[0] = 8
after Get semaphore ...
semval[0] = 7
before release semaphore exclusively...
semval[0] = 7
before release semaphore exclusively...
semval[0] = 8
Administrator@node1 ~
$ ./a.exe ( the second running, gets semaphore and releases
semaphore successfully)
Test semaphore has existed.
Get test semaphore...
semval[0] = 8
Get test semaphore successfully.
before Get semaphore exclusively...
semval[0] = 8
after Get semaphore ...
semval[0] = 7
before release semaphore exclusively...
semval[0] = 7
before release semaphore exclusively...
semval[0] = 8
Administrator@node1 ~
$ ./a.exe ( the third running, gets semaphore
successfully,but fails to release semaphore )
Test semaphore has existed.
Get test semaphore...
semval[0] = 8
Get test semaphore successfully.
before Get semaphore exclusively...
semval[0] = 8
after Get semaphore ...
semval[0] = 7
before release semaphore exclusively...
Administrator@node1 ~
$ ./a.exe ( the fourth running, proves that the third running
didnot release semephore when aborting , a bug ????)
Test semaphore has existed.
Get test semaphore...
semval[0] = 7
Get test semaphore successfully.
before Get semaphore exclusively...
semval[0] = 7
after Get semaphore ...
semval[0] = 6
before release semaphore exclusively...
semval[0] = 6
before release semaphore exclusively...
semval[0] = 7
Administrator@node1 ~
$ */
[-- Attachment #2: lcctestsem.c --]
[-- Type: application/octet-stream, Size: 3218 bytes --]
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <net/if.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#define TESTSEMID 100
#define SEMSIZE 1
#if defined(__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED)
/* union semun is defined by including <sys/sem.h> */
#else
/* according to X/OPEN we have to define it ourselves */
union semun {
int16_t val; /* value for SETVAL */
struct semid_ds *buf; /* buffer for IPC_STAT, IPC_SET */
unsigned short int *array; /* array for GETALL, SETALL */
struct seminfo *__buf; /* buffer for IPC_INFO */
};
#endif
int test_semid;
void
to_show(){
union semun arg;
unsigned short int allval[SEMSIZE];
int i;
arg.array = allval;
if (semctl(test_semid, 0 , GETALL, arg) < 0) {
printf("semctl failed for[%s].\n", strerror(errno));
return ;
}
for( i=0; i < SEMSIZE; i++)
printf("\t semval[%d] = %d \n", i , allval[i]);
return;
}
int
create_test_semaphore(void)
{
int key, i;
char fn[100];
union semun arg;
unsigned short int allval[SEMSIZE];
sprintf(fn, ".");
if ((key = ftok(fn, TESTSEMID)) < 0) {
printf("ftok failed for[%s].\n", strerror(errno));
return -1;
}
if ((test_semid = semget(key, SEMSIZE, IPC_CREAT | IPC_EXCL | 0666)) < 0) {
if (errno == EEXIST) {
printf("Test semaphore has existed.\n");
printf("Get test semaphore...\n");
if ((test_semid = semget(key, 0, 0666)) < 0) {
printf("semget failed for[%s].\n", strerror(errno));
return -1;
} else {
to_show();
printf("Get test semaphore successfully.\n");
return 0;
}
}
printf("semget failed[%s].\n", strerror(errno));
return -1;
}
for (i = 0; i< SEMSIZE; i++)
allval[i] = 8;
arg.array = allval;
if (semctl(test_semid, SEMSIZE, SETALL, arg) < 0) {
printf("semctl failed for[%s].\n", strerror(errno));
return -1;
}
return 0;
}
int
mutex_op_semaphore(int op)
{
int i;
struct sembuf oparray[SEMSIZE];
for (i = 0; i < SEMSIZE; i++) {
oparray[i].sem_num = i;
oparray[i].sem_op = op;
oparray[i].sem_flg = SEM_UNDO;
}
if (semop(test_semid, oparray, SEMSIZE) < 0) {
printf("semop failed for[%s].\n", strerror(errno));
return -1;
} else
return 0;
}
int
main(void)
{
int ret;
// printf("Create test semaphore...\n");
if (create_test_semaphore() < 0) {
printf("Create test semaphore failed.\n");
return -1;
} //else
//printf("Create test semaphore successfully.\n");
printf("before Get semaphore exclusively...\n");
to_show();
if (mutex_op_semaphore(-1) < 0) {
printf("Get test semaphore failed.\n");
return -1;
} else
printf("after Get semaphore ...\n");
to_show();
sleep(5);
printf("before release semaphore exclusively...\n");
to_show();
if (mutex_op_semaphore(1) < 0) {
printf("Release test semaphore failed.\n");
return -1;
} else
printf("before release semaphore exclusively...\n");
to_show();
return 0;
}
[-- Attachment #3: Type: text/plain, Size: 218 bytes --]
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: problem about SEMAPHORE at cygwin 1.5.7
2004-03-01 4:33 problem about SEMAPHORE at cygwin 1.5.7 xuzhd
@ 2004-03-02 11:33 ` Corinna Vinschen
0 siblings, 0 replies; 2+ messages in thread
From: Corinna Vinschen @ 2004-03-02 11:33 UTC (permalink / raw)
To: cygwin
On Mar 1 12:36, xuzhd@Lenovo.com wrote:
> (See attached file: lcctestsem.c)
>
> problem about SEMAPHORE at cygwin 1.5.7
>
> cygwin 1.5.7
> cygserver as ipc server
>
> a process has gotten semaphore using SEM_UNDO, when the process aborts, it
> should release corresponding semaphore at Linux.But at Cygwin 1.5.7,1.5.4,
> 1.3.22, I cannot prove it. is it a bug to cygwin ? thank you
Yes, it's a bug in Cygserver. Thanks for the testcase! It helped to
track down the problem. I've checked in a fix to Cygserver. It will
show up in the next developers snapshot (http://cygwin.com/snapshots/).
Thanks again,
Corinna
--
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Developer mailto:cygwin@cygwin.com
Red Hat, Inc.
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2004-03-02 11:11 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-01 4:33 problem about SEMAPHORE at cygwin 1.5.7 xuzhd
2004-03-02 11:33 ` Corinna Vinschen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).