Safe Programming Methods¶
Lecturer: dr hab. inż. Paweł T. Wojciechowski, prof. PP
Web page in e-kursy: https://ekursy.put.poznan.pl/course/view.php?id=37629
WYNIKI ZALICZENIA:
Consultation: by e-mail
Over the past decades, Moore’s law has been in force: “the number of transistors in an integrated circuit doubles about every two years”. Each new generation of processors made the programs to work faster. However, this trend is changing. The future computer systems will have more and more CPU multi-core units, but each individual unit will not be faster than the unit from the previous year. Thus, to fully utilize the hardware capabilities, computations must be carried out concurrently.
Unfortunately, writing concurrent programs for contemporary computer architectures, which do not guarantee sequential consistency, is usually significantly more difficult than writing analogous sequential programs. In addition, testing such programs is difficult, and detecting and removing all programming errors in the code is not always possible.
The purpose of the lectures is to discuss some programming methods that allow you to write concurrent programs that are correct and efficient. Firstly, we will see how to use monitors correctly and efficiently. Next, we will discuss the alternative synchronization method, i.e. transaction memory. Secondly, we will present selected automatic verification methods. Thirdly, we will discuss some issues regarding the correctness of concurrent programs aimed for modern computer architectures. Finally, we will show example methods and languages that make it easy writing of parallel and distributed programs.
Below is a list of topics (Summer term 2024):
Safe concurrency (lectures)¶
Date |
Synopsis, articles, and other materials |
Slides |
---|---|---|
28.02 |
Discussion of the scope of the course and the form of assessment. |
|
6.03 |
Repetition of selected material from the Concurrent and system programming course: Sections 1, 2, and 7 (only monitors). |
|
13.03, 20.03 |
Concurrent programming and synchronization on the example of monitors in C# or Java:
|
|
27.03 |
Detection of the race condition during program execution on the example of the Eraser tool: the lockset algorithm and its optimization (an initialization of variables, read-only shared data, read-write locks), correctness and completeness of the algorithm. Eraser: A Dynamic Data Race Detector for Multithreaded Programs |
|
3.04 |
Detection of the high-level data race condition by static analysis: the algorithm and its correctness and completeness (false positives – unnecessary warnings, false negatives – unnoticed errors). |
|
10.04 |
Detection of programming errors (divide by zero, race condition, deadlock) based on model checking, on the example of the Java Pathfinder tool. |
|
17.04 |
Conditional critical regions (CCR) and transactional memory: low-level operations on transactional memory, an implementation of CCR using these operations, data structures (ownership records and transaction descriptors), an algorithm of atomic writing to transactional memory. |
|
24.04 |
Correctness of concurrent access to shared objects: sequential and concurrent histories, the linearizability property, concurrent FIFO queue and register, linearizability properties: locality (or compositionality) and non-blocking. Linearizability: A Correctness Condition for Concurrent Objects |
|
8.05, 22.05 |
Memory model on the example of Java language:
|
|
29.05 |
Parallel programming on the example of the Cilk language: programming constructs, the acyclic directed graph (DAG) as a model of multithreaded computing, performance measures on a multi-core processor, greedy scheduling and upper limits for computation time. A Minicourse on Multithreaded Programming Further reading (not obligatory): OpenCilk: A Modular and Extensible Software Infrastructure for Fast Task-Parallel Code |
|
05.06 |
Distributed programming with guarantees of eventual consistency on the example of cloud types and conflict-free replicated types (CRDTs). Cloud Types for Eventual Consistency Conflict-free Replicated Data Types Further reading (not obligatory): A Comprehensive Study of Convergent and Commutative Replicated Data Types |
|
7.06 @ 8:00, s. L122 BT |
Colloquium |
|
7.06 @ 9:45, s. 45 CW |
odrobienie zajęć lab. z 15.05 @ 9:45 (grupa A) |
|
7.06 @ 11:15, s. 45 CW |
odrobienie zajęć lab. z 15.05 @ 15:10 (grupa B) |
|
12.06 |
Distributed programming in the message-passing model on the example of the Erlang language (actors model, fault tolerance) and/or the Nomadic Pict language (process mobility, verification of the correctness of communication during compilation by static types). Typed First-Class Communication Channels and Mobility for Concurrent Scripting Languages Further reading (not obligatory): |
The OCaml language (labs)¶
There are two dominant paradigms in programming, functional and imperative. The goal of the lab. course is to provide an introduction to functional programming. Functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids changing state and mutable data. During the course, we learn OCaml, a popular statically-typed functional programming language with an emphasis on expressiveness and safety.
Though languages and technologies change rapidly, many key ideas underlying the theory and practice of functional programming are immutable. The course will expose you to some of those ideas. The main topics raised during the course include:
Mathematical expressions and operators, comparison operators, boolean operators, programs as expressions.
Names, functions, basic types (int, float, string, char), type checking, type inference, type polymorphism (type variables).
Functions upon functions, anonymous functions (lambda expressions), partial function application (we apply only some of the arguments).
References (as an example of side effects).
Basic data types: lists, tuples, records.
Patterns and pattern matching.
List mapping, filtering, and folding.
Recursive functions, tail recursive functions (necessary in OCaml).
Exceptions and exception handlers.
Defining new types: constructors, polymorphism, recursive definitions.
Defining modules (sets of functions): abstraction, interfaces, functors.
Designing a library of polymorphic binary search trees (dictionaries).
Maps (dictionaries).
Mutable arrays.
Loops (while, for).
System programming: I/O operations, using files, graphics.
Example exercises:
Implement a function
but-last
, which takes a listl : 'a List
as the only argument, and returnsl
without the last element. Try to implement this function in two variants: non-tail recursive and tail recursive. variants of this function.Implement a function
len
which computes the number of elements in the list usingfold_right
ifold_left
.Implement a function
reverse
which reverses the order of the elements on the list.Define a function
append
, which concatenates two lists, using a functionList.fold_right
.Define two modules
Inttree
andTree
implementing binary trees, with values in leafs of typeInt
and of any type. The interfaces are specified here.Create a module
LMap
from a standard moduleMap
, which implements a map (dictionary) in which a key is a list of any type, and a value is of typeInt
. Two keys are identical if they have the same first element. Try all functions of the moduleLMap
which were used for the standard moduleMap
here.
The code snippets and solutions of the exercises: lab. 1, lab. 2, lab. 3, lab. 4, lab. 5, lab. 6, lab. 7, lab. 8, tree module, graphics, sys functions.
Below are some useful links.
The OCaml home pages:
On-line editors (good for learning):
Here are some OCaml textbooks that you might find useful:
OCaml from the Very Beginning (HTML | PDF)
A very gentle introductory treatment of OCaml programming. Each small, self-contained chapter introduces a new topic in tutorial style.
OCaml Programming: Correct + Efficient + Beautiful
“A textbook on functional programming and data structures in OCaml, with an emphasis on semantics and software engineering. This book is the textbook for CS 3110 Data Structures and Functional Programming at Cornell University.”
Introduction to Objective Caml
“This book presents a practical introduction and guide to the language, with topics ranging from how to write a program to the concepts and conventions that affect how programs are developed in OCaml.”
Real World OCaml - Functional Programming for the Masses
“We wrote this book because we believe in the importance of programming languages, and that OCaml in particular is an important language to learn. Both of us have been using OCaml in our academic and professional lives for over 20 years, and in that time we’ve come to see it as a powerful tool for building complex software systems.”
Developing Applications with Objective Caml (in PDF)
A comprehensive, but a bit outdated, book on OCaml, covering not only the core language, but also modules, objects and classes, threads and systems programming, interoperability with C, and runtime tools.
Unix system programming in OCaml (in PDF)
This is an introductory course on Unix system programming, with an emphasis on communications between processes. The authors use OCaml instead of the C language that is customary in systems programming.
Using, Understanding, and Unraveling the OCaml Language: From Practice to Theory and vice versa (in PDF)
These course notes provide a formal description of the operational semantics (evaluation) and statics semantics (type checking) of core ML and of several extensions that appeared in OCaml (which originated from the ML language).
This document was generated on Aug 21, 2024.