Facebook
From Denim Moth, 3 Years ago, written in C#.
This paste is a reply to Re: Re: ss from Colossal Bushbaby - go back
Embed
Viewing differences between Re: Re: ss and Re: Re: Re: ss
#include h>
h> ...operacje wejścia/wyjścia
#include  ...maski uprawnień (choć niekonieczne)
#include  ...stała OCREAT
#include h>
h> ...semafory POSIX, w ogólności (konieczne)
int main( int argc,char **argv )
{
 sem_t id;
*id; ...identyfikator tworzonego semafora
 
int counter;
counter; ...licznik semafora (pomocniczo)
 char name[] = "km"; ...nazwa semafora (jeżeli nazwany, jakaś musi
być)
niektóre implementacje semaforów POSIX
wymagają aby nazwa zaczynała się od '/',
czyli będzie
char name[] = "km";
 
counter = 7;
if( !sem_init( &id,0,counter ) )
7; ...inicjujemy zmienną dla licznika
...spróbujmy w takim razie utworzyć/otworzyć semafor (nazwany)
if((id=sem_open(name,O_CREAT,S_IRUSR|S_IWUSR,(unsigned)counter))!=SEM_FAILED)
{
...jeżeli się udało, to ciąg dalszy
printf( "*** inicjacja semafor\n" otwarto semafor\t%s\n",name );
if( !sem_getvalue( &id,&counter id,&counter )
) ...odczyt licznika
{ printf( " licznik semafora\t%d\n",counter ); }
else{ perror( "*** sem_getvalue()\t" ); }
if( !sem_destroy( &id !sem_close( id ) ){ printf( "*** usunięcie semafor\n" zamknięto semafor\t%s\n",name ); }
else{ perror( "*** sem_destroy()\t" sem_close()\t" ); }
/*...na wstępie pozostawmy te linie w komentarzu
if( !sem_unlink( name ) ){ printf( "*** usunięto semafor\t%s\n",name ); }
else{ perror( "*** sem_unlink()\t" ); }
*/
}
else{ perror( "....sem_init()....sem_open()...." ); }
 
} ...cóż, gdyby coś poszło nie tak
return 0;
}

Replies to Re: Re: Re: ss rss

Title Name Language When
Re: Re: Re: Re: ss Smelly Gibbon csharp 3 Years ago.