Semaphore is a leading offshore software development company. With over 500+ employees, 15+ years of rich experience and with 1000+ Offshore Software Projects developed successfully, Semaphore can assist you in any of your requirements for Software Development, Website Design and Development, Mobile Application Development, Internet/Intranet Solutions, E-Commerce Solutions, Legacy Application Re-engineering, Search Engine Optimization and Marketing and Business Process Outsourcing.
We at Semaphore have expertise in core technologies like Microsoft .Net, Oracle, SAP, LAMP, Windows Mobile Applications, PHP and Open Source like Joomla, OsCommerce, Zend, and Coldfusion. We also have expertise working on Java Platform (J2ME, JSP, Servlets, Struts, Spring, EJB, Hibernate, etc.). We also offer Offshore Staff Augmentation services (Offshore manpower resource services) at attractive prices and help you setup an offshore or remote IT office.
Semaphore is a leading offshore software development company. With over 500+ employees, 15+ years of rich experience and with 1000+ Offshore Software Projects developed successfully, Semaphore can assist you in any of your requirements for Software Development, Website Design and Development, Mobile Application Development, Internet/Intranet Solutions, E-Commerce Solutions, Legacy Application Re-engineering, Search Engine Optimization and Marketing and Business Process Outsourcing.
We at Semaphore have expertise in core technologies like Microsoft .Net, Oracle, SAP, LAMP, Windows Mobile Applications, PHP and Open Source like Joomla, OsCommerce, Zend, and Coldfusion. We also have expertise working on Java Platform (J2ME, JSP, Servlets, Struts, Spring, EJB, Hibernate, etc.). We also offer Offshore Staff Augmentation services (Offshore manpower resource services) at attractive prices and help you setup an offshore or remote IT office.
Διδακτέα - Εξεταστέα ύλη για το μάθημα "Οικονομία" (ΑΟΘ) της Γ τάξης του Επαγγελματικού λυκείου. Μπορείτε να δείτε και αναλυτικά την ύλη του μαθήματος επιλέγοντας τον παρακάτω σύνδεσμο:
https://view.genially.com/6450d17ad94e2600194eb286
5. Είναι ένας τύπος μεταβλητής που δίνει ένα μηχανισμό συγχρονισμού διεργασιών
για την αποκλειστική διαχείριση κοινών πόρων
Ο χειρισμός των semaphores υλοποιείται από δύο εντολές:
- P / down
- V / up
Αν -κατά την κλήση της down- η τιμή της semaphore είναι 0,
η καλούσα διεργασία θα μπλοκαριστεί
5
6. int semget(key_t key, int nsems, int semflg);
Επιστρέφει το semaphore identifier
για ένα array nsems semaphores
που συνδέεται με το key
και δικαιώματα-πρόσθετες απαιτήσεις semflg
int sid;
key_t skey;
int ns;
int sflag;
int main()
{
skey = 1234;
ns = 1;
sflag = 0666 | IPC_CREAT;
if ((sid = semget(skey, ns, sflag)) == -1) { perror("semget"); exit(1); }
printf("Semget succeed! SID=%dn", sid);
exit(0);
}
6
7. int semctl(int sid, int snum, int cmd, union semun arg);
Εκτελεί την ενέργεια cmd
στο snum element (δηλ. semaphore)
του semaphore array με ταυτότητα sid
με το arg μεταφέρονται τιμές από/προς το semaphore array
union semun {
int val;
struct semid_ds *buff;
unsigned short *array;
};
SETVAL
GETVAL
SETALL
GETALL
IPC_RMID
7
8. int main(void) /* semSetUp.c */
{ key_t skey;
int sid;
union semun{ int val; struct semid_ds *buff; unsigned short *array; } arg;
skey = 1234;
if ((sid = semget(skey, 1, 0666 | IPC_CREAT)) == -1) { perror("semget"); exit(1); }
printf("Successful creation of semaphore set!n");
printf("Semaphore ID=%d on KEY=%dn", sid, skey);
arg.val = 1; /* αρχικοποίηση του 0 semaphore με τιμή 1 */
if (semctl(sid, 0, SETVAL, arg) == -1){ perror("semctl"); exit(1); }
printf("New Semaphore VALUE=%dn", arg.val);
return 0;
}
8
9. int main(void){ /* semDeletion.c */
key_t skey;
int sid;
union semun{ int val; struct semid_ds *buff; unsigned short *array; } arg;
skey = 1234;
/* δέσμευση του semaphore */
if ((sid = semget(skey, 1, 0)) == -1) { perror("semget"); exit(1); }
printf("Semaphore ID=%d on KEY=%dn", sid, skey);
if (semctl(sid, 0, IPC_RMID, arg) == -1){ perror("semctl"); exit(1); }
printf("Successful semaphore deletion!n");
return 0;
}
9
10. int semop(int sid, struct sembuf *opstr, int nops);
- ενεργεί στο semaphore array,
- η δομή struct sembuf { short snum; short sop; short sflag; }; ορίζει το είδος της
ενέργειας -DOWN / UP- που θα συμβεί
- η παράμετρος nops είναι ο αριθμός των struct sembuf (προφανώς μία για κάθε semaphore)
int main(void)
{
key_t skey;
int sid;
struct sembuf sb = { 0, -1, 0 }; // πρώτη semaphore, DOWN setup
skey = 1234;
10
11. if ((sid = semget(skey, 1, 0)) == -1){ perror("semget"); exit(1); }
printf("nnGrap hold of semSetUp.c semaphore ");
printf("with SID=%d on KEY=%dn",sid,skey);
printf("n< < Press ENTER to block the target > >");
getchar();
printf("Trying to block the target...n");
/* DOWN */
if (semop(sid, &sb, 1) == -1){ perror("semop"); exit(1); }
printf("Blocked!!!nnn< < < Press ENTER to unblock > > > ");
getchar();
sb.sem_op = 1;
/* UP */
if (semop(sid, &sb, 1) == -1) { perror("semop"); exit(1); }
printf("Unblocked!nn");
return 0;
}
11
12. int main()
{
int sid;
union semun sem_val;
int child_pid, i, rc;
sid = semget(SKEY, 1, IPC_CREAT | 0600);
if (sid == -1)
{
perror("main: semget");
exit(1);
}
sem_val.val = 1;
rc = semctl(sid, 0, SETVAL, sem_val);
if (rc == -1)
{
perror("main: semctl");
exit(1);
}
12
13. for (i=0; i<NUM_PROCS; i++)
{ child_pid = fork();
switch(child_pid)
{ case -1: perror("fork");
exit(1);
case 0: do_child_loop(sid, FILE_NAME);
exit(0);
default: break;
} // switch
}
for (i=0; i<NUM_PROCS; i++)
{ int child_status;
wait(&child_status);
}
printf("main: all donen");
fflush(stdout);
}
13
14. void do_child_loop(int sem_set_id, char* file)
{
pid_t pid = getpid();
int i, j;
for (i=0; i<3; i++)
{
update_file(sem_set_id, file, pid);
for (j=0; j<DELAY; j++)
;
}
}
14