Showing posts with label operating systems. Show all posts
Showing posts with label operating systems. Show all posts

relocatable address

The address generated by the compiler are relocatable addresses.
See : Introduction to computer-based imaging systems By Divyendu Sinha, Edward R. Dougherty , page.213 :
Assuming the page size as 64 KB (216):
The compiler generated relocatable addresses as if the entire program were to be loaded at once. The page number and offset can be easily computed from the relocatable address. Since the offset must be a nonnegative number smaller than the page size, the offset is the least significant 16 bits of the relocatable address. The remaining 25-16 = 9 bits specify the page number. Consider the relocatable address 145678. Since

145678 (decimal) = 0 00000010 00111001 00001110 (binary),
we have the page number as 2 (or 000000010 in binary) and the offset as 14,606( or 0011100100001110 in binary).

If the page size is changed later on to 32KB, programs need not be recompiled to run on the system. Computation of page number and offset is done by the memory manager

Different types of mutexes

Some of the different types of Mutex:
-- Fair / Unfair Mutex : A mutex which allows access in the order of locking
-- Reentrant : which allows recursive locking, helpful when there are recursive calls in the code. See also man page description of PTHREAD_MUTEX_RECURSIVE
-- Scalable Mutex
-- Sleep or spin : spin is optimal for short waits and sleep for long waits. And also while spining, there is no need for context switch.

Reference : Intel threading building blocks: outfitting C++ for multi-core processor ... By James Reinders, p.114

Condition variables

Explain condition variables, and how they are used in conjuction with a mutex.

Answer:[1][2][3]

Difference between fork(), clone().

What is the difference between fork(), clone(), and pthread_create() system calls.?

Answer:

Excepts from the manpage:++

clone() creates a new process, in a manner similar to fork(). It is actually a library function layered on top of the underlying clone() system call, hereinafter referred to as sys_clone.

Unlike fork(), these calls allow the child process to share parts of its execution context with the calling process, such as the memory space, the table of file descriptors, and the table of signal handlers.

The main use of clone() is to implement threads: multiple threads of control in a program that run concurrently in a shared memory space.

When the child process is created with clone(), it executes the function application fn(arg). (This differs from fork(), where execution continues in the child from the point of the fork() call.) The fn argument is a pointer to a function that is called by the child process at the beginning of its execution. The arg argument is passed to the fn function.

See also:[2]

Difference between mutex and a semaphore

What is the difference between a mutex and a semaphore?

Answer:

According to Operating Systems by William Stallings (2008)*
-

Mutex is a binary semaphore (A semaphore that takes on only the values 0 and 1). The Key difference between the two is that the process that locks the mutex (sets the value to zero) must be one to unlock it (sets the value to 1).

According to "Professional C# 2005 with .NET 3.0
By Christian Nagel, Bill Evjen, Jay Glynn, Karli Watson, Morgan Skinner" -

A Semaphore can be used by mutliple threads (depending on the count) at once.

In brief,*
- By semaphore we actually mean counting semaphore. By mutex we actually mean mutex semaphore. A mutex is essentially a binary semaphore. You can replace any Mutex with a Semaphore of MaxCount 1.


- Mutexes are usually more efficient than binary semaphores.


- Mutex has an owner concept: unlocking a mutex can be only done by the thread that locked (or, equivalently, "owns") the mutex.