Sistemi operativi, A.A. 2011/2012 (M. Cesati) Scaletta esercitazione #10, 17.05.2012 1 Cambiare il puntatore corrente al file in stdio 1.1 Chiamate di sistema fseek(), ftell(), rewind() fgetpos(), fsetpos(): +--------------------------------------------------+ |int fseek(FILE *stream, long offset, int whence); | |long ftell(FILE *stream); | |void rewind(FILE *stream); | |int fgetpos(FILE *stream, fpos_t *pos); | |int fsetpos(FILE *stream, fpos_t *pos); | +--------------------------------------------------+ 2 Funzioni di base della libreria Pthread 2.1 Funzione pthread_create() +-----------------------------------------------------------------+ |int pthread_create(pthread_t *thread, const pthread_attr_t *attr,| | void *(*start_routine) (void *), void *arg); | +-----------------------------------------------------------------+ 2.2 Funzione pthread_self() +-----------------------------+ |pthread_t pthread_self(void);| +-----------------------------+ 2.3 Funzione pthread_exit() +--------------------------------+ |void pthread_exit(void *retval);| +--------------------------------+ 2.4 Funzione pthread_join() +--------------------------------------------------+ |int pthread_join(pthread_t thread, void **retval);| +--------------------------------------------------+ 3 Esercizio: Modificare il programma 'mandelbrot3' in modo che utilizzi quattro thread POSIX invece che tre processi (la scrittura del file deve essere effettuata da un unico thread) [mandelbrot4.c] 3.1 Per compilare con la libreria PThread e' necessario usare il flag -pthread. E' necessario modificare il Makefile: +-------------------------------------+ |CC=gcc | |CFLAGS=-Wall -Wextra -O2 | |CFILES=$(shell ls *.c) | |PROGS=$(CFILES:%.c=%) | | | |all: $(PROGS) | | | |mandelbrot4: mandelbrot4.c | | $(CC) $(CFLAGS) -pthread -o $@ $^ | | | |clean: | | rm -f $(PROGS) *.o | +-------------------------------------+ ==========