Operating Systems 173323 (3 cu)

Exercise 7

Week 48

Exercises 7 are in computer classes:

Group 1: on Monday Nov. 26 at 16-18 in T/B178
Group 2: on Friday Nov. 30 at 8-10 in T/B178

  1. A thread shares with other threads belonging to the same process its code section, data section, and other OS-resources. Consider the following c-program, which uses Pthreads of POSIX standard defining an Application Programming Interface (API). Start with man threads and add comment lines to the following program for explaining the program code. Compile the program in cs-computer and execute it. Think what benefits threads can provide.

    http://cs.joensuu.fi/pages/mhk/harjoitukset/kj/h7/pthread_example.c

  2. Consider the Peterson algorithm, which was introduced in lectures (Algorithm 3) for solving the critical-section problem. Show that this algorithm satisfies mutual exclusion, progress, and bounded waiting requirements.

  3. A communication between processes over a network can be implemented using sockets. A socket is made up using an IP-address with a port number. Consider the following c-programs, in which socket_server works as a server by listening to a specified port. Client socket_client will send a request for server, and server accepts a connection from the client to complete the connection.

    Explain the usage of the sockets in the following programs. Compile them and execute in cs-computer. Execute first the server and then execute client, in separate sessions. You can try also a connection from other machine connected to internet.

    http://cs.joensuu.fi/pages/mhk/harjoitukset/kj/h7/socket_server.c

    http://cs.joensuu.fi/pages/mhk/harjoitukset/kj/h7/socket_client.c