K
kvnsmnsn
I'm taking a class on Internet Programming, and the lab I'm currently
working on requires us to use threads and semaphores. I'm looking at
a slide from that class titled "Unix Semaphore Code" that says:
[] Creation
o union semun arguments;
o key_t key = 1;
o int flags = 0777 | IPC_CREAT;
o int semid = semget(key, 1, flags);
o argument.val = initialvalue;
o semctl(semid, 0, SETVAL, argument);
[] Destruction
o int ignored_int;
o union semun ignored;
o semctl(semid, ignored_int, IPC_RMID, ignored);
I wanted to create an array of two semaphores, so I wrote the follow-
ing <main> function:
int main ( int argCount
, char** arguments)
{
pthread_t Write[ 2];
union semun argument; <=================
key_t key = 1;
int flags = 0700 | IPC_CREAT;
int before[ 2];
int pairs[ 2][ 2];
int result;
int parity;
int end;
printf( "Before creation of semaphores.\n");
for (parity = EVEN; parity <= ODD; parity++)
{ before[ parity] = semget( key, 1, flags);
argument.val = parity;
semctl( before[ parity], 0, SETVAL, argument);
}
...
But when I try to compile it I get the error message
"CountSharer.c:44: error: storage size of 'argument' isn't known".
Line 44 is the line my arrow is pointing to up above. The slide up
above is the only reference to <union semun> that I know of. Does
anyone know what I need to do to my <argument> variable to keep this
error from occurring?
---Kevin Simonson
"You'll never get to heaven, or even to LA,
if you don't believe there's a way."
from _Why Not_
working on requires us to use threads and semaphores. I'm looking at
a slide from that class titled "Unix Semaphore Code" that says:
[] Creation
o union semun arguments;
o key_t key = 1;
o int flags = 0777 | IPC_CREAT;
o int semid = semget(key, 1, flags);
o argument.val = initialvalue;
o semctl(semid, 0, SETVAL, argument);
[] Destruction
o int ignored_int;
o union semun ignored;
o semctl(semid, ignored_int, IPC_RMID, ignored);
I wanted to create an array of two semaphores, so I wrote the follow-
ing <main> function:
int main ( int argCount
, char** arguments)
{
pthread_t Write[ 2];
union semun argument; <=================
key_t key = 1;
int flags = 0700 | IPC_CREAT;
int before[ 2];
int pairs[ 2][ 2];
int result;
int parity;
int end;
printf( "Before creation of semaphores.\n");
for (parity = EVEN; parity <= ODD; parity++)
{ before[ parity] = semget( key, 1, flags);
argument.val = parity;
semctl( before[ parity], 0, SETVAL, argument);
}
...
But when I try to compile it I get the error message
"CountSharer.c:44: error: storage size of 'argument' isn't known".
Line 44 is the line my arrow is pointing to up above. The slide up
above is the only reference to <union semun> that I know of. Does
anyone know what I need to do to my <argument> variable to keep this
error from occurring?
---Kevin Simonson
"You'll never get to heaven, or even to LA,
if you don't believe there's a way."
from _Why Not_