1. Introduction 2. Threads 3. Fair Thread Framework 4. Java FairThreads API 5. Examples 6. Links with Reactive Programming 7. Conclusion |
Contrary to standard sequential programming where the processor executes a single program, in concurrent programming the processor is a shared resource which is dispatched to several programs. The term concurrent is appropriate because programs can be seen as concurrently competing to gain access to the processor, in order to execute. Threads are a basic mean for concurrent programming, and are widely used in operating systems. They are also introduced in the Java language as first-class primitive. At language level, threads offer a way to structure programs by decomposing systems in several concurrent components; in this respect, threads are useful for modularity. However, threads are generally considered as low-level primitives leading to over-complex programming. Moreover, threads generally have loose semantics, in particular depending on the underlying executing platform; to give them a precise semantics is a difficult task, and this is a clearly identified problem to get portable code. This paper proposes a new framework with clear and simple semantics, and with an efficient implementation. In it, threads are called fair; basically, a fair thread is a cooperative thread executed in a context in which all threads always have equal access to the processor. Fair threads have a deterministic semantics, relying on previous work belonging to the so-called reactive approach. The structure of the paper is as follows: section Threads introduces threads and scheduling strategies; the FairThreads framework is defined in section Fair Thread Framework; section Java FairThreads API contains the Java API for using FairThreads; three examples are given in section Examples; finally, links with the reactive approach, which is at the basis of the fair thread proposal, are considered in section Links with Reactive Programming. |