Hot answers tagged

4

Here's a tricky interleaving. R1,R2 denote the independent logical registers used by the threads, while count is the shared variable in memory. Thread 1 starts its first iteration, performing only a read. count=0, R1=0, R2=? Thread 2 performs 99 iterations. count=99, R1=0, R2=99 Thread 1 completes its first iteration (increment and write). count=1, R1=1, R2=...


3

A fair mutex will spend more of its lifetime locked than an unfair mutex, all else being equal. Because a thread releasing an unfair mutex can always just unlock it. But a thread releasing a fair mutex can only unlock it when the waiter queue is empty. Otherwise, the releasing thread must leave the mutex locked for the sake of the next thread, aka the first ...


2

"Unit of dispatch" just means "the thing that gets scheduled."


1

The code is far from optimal, if you instead use a condition variable it is much clearer: struct mylock { pthread_cond_t entry; pthread_mutex_t manager; int counter; int state; } void mylock_acquire(struct mylock *lock, int state) { assert(state != 0); pthread_mutex_lock(&lock->manager); while (lock->state != 0 &&...


1

I don't get where the 0.375 came from ? If the CPU utilization is 75%, and it's shared equally between two process, each of them gets 37.5%. What are CPU minutes? A CPU-minute is the amount of work done by one CPU in one minute.


1

For full detail, you should consult a textbook on operating systems. The brief answer is that the operating system doesn't need to be executing all the time. It suffices for it to periodically regain control of the machine, and this happens through so-called "interrupts". Interrupts can happen for a number of reasons: a process that wants the operating ...


1

It may be helpful to show the motivation for this kind of parallelism. Compared to other components (such as memory access), computation, especially adding/subtraction, is cheap on chips. It takes very little space, relatively, to add another adder - and of course that adder could be used for address calculations as well as for actual arithmetic. So more ...


1

Actually, there is such a model, though it is typically not thought of as one of the "multi-threading models." One to many would mean one thread distributed across many processors. At first that should look silly. After all, you only have one thread. What are the other processors to do? However, superscalar architectures are designed to do roughly this ...


Only top voted, non community-wiki answers of a minimum length are eligible