Thursday, July 13, 2006

Still breathing

I've failed to blog for a while.. again. Can't seem to make a habit out of this. :-/

I've been working as a summer trainee at one of the labs of our Comp. Sci. department, turning a certain Java Swing-based application into an Eclipse plug-in. It's been quite fun so far, few bumps here and there but nothing we haven't been able to solve.

I'm having my only week of holiday now. I spent couple of day at my godfather's summer cottage which was pretty nice and relaxing.

I'm writing this on my new Macbook, on which I blew most of my first salary. It's pretty cool, still figuring out the quirks of the Apple's user interface logic. Only one real dislike so far: it does get frigging hot!



Saturday, May 27, 2006

Course Summary Part 1

I'll start with the courses of the Fall semester

Basic Course in Mathematics C3

The third and final basic math course in the CS program. The first half was pretty much Linear Algebra (matrices, eigenvalues/vectors etc, matrix exponent..) and then using them to solve systems of differential equations. Laplace transform was also introduced as an alternative to solving those problems.
not.
The first half was a bit scary at first because I had managed to miss the Mathematics 1 for CS program where the basic matrix algebra was taught so I had very little knowledge of them and the lecturer used about half of the first lecture to review the basics. I had to do extra study and eventually got the hang of it.

The second part of the course was about Complex Analysis, Complex Integration, Z-transform and Fourier Series.. (there was no time for Fourier Transforms though). The complex analysis and integration stuff was a bit weird. Lots of big theorems and scary proofs but in the end I didn't quite get where these are used in practice. I guess for example electrical engineers dabble more in the complex world.

At least the Fourier Series' in the end seemed somewhat useful and were pretty cool despite the amount of work even the simple exercises required.

This was an okay course, the problem sets were somewhat laborious and sometimes the two hour long proofs of some theorem caused hair loss but. Still I'm glad the basic math courses are over. There's still a course in discrete mathematics ahead though.

Applied Probability

More math. This is one of those courses in addition to the math and physics courses that all the departments of the university have in their undergraduate programs. There are different levels of difficulty. The probability and statistics course has a tougher A version which is more theoretical and has more probability theory than statistics. I took the easier B course which was half probability, half statistics. This was an easy course although the lecturer was far from inspiring so a medium lack of motivation made it at least seem harder than it was.

Introduction to Theoretical Computer Science

Well.. theoretical computer science. Finite automata, regular languages, context-free grammars, Turing machines, computability theory. This course frightened me. I had seen some problem sets and lecture notes before the course began and they seemed pure gibberish with more Greek letters than Roman. In the end the course turned out to be quite interesting. It was a bit tough towards the end with Turing machines and computability theory.

I overheard many people complain that the course is useless since there's no use for this stuff in practice. Well it was very theoretical as the name already implies but for example regular expressions are very practical in reality and I also learned their limitations. The Turing machines also provided insight into how the computer works and what kind of things it can do and what is simply impossible. Knowing the concepts of the course at this introductory level is in my opinion something that everyone calling themselves computer science students should know. I know that I won't take TCS as a major but I now have a general idea of what it's about and I respect the people doing research in that area.

That's not all but I'm already exhausted from writing, more later.

Wednesday, May 24, 2006

School's out!

The finals are over at last. I somehow managed to pull them all off pretty well (although the results aren't in yet) even though there were several moments of desperation while trying to study for the seven exams, especially the last two which were on the same day only few hours apart.

At least I once again proved to myself that I can do this stuff, no matter how tough it seems. And still I always stress the hell out of myself.. I should probably take a little less classes next year. Then again that was the plan this year and I ended up taking even more. And despite the heavy course load I managed to torment my liver in numerous festivities so I guess it's a win-win.

I'm planning to write short summaries of the courses I took this year and what I thought of them.

Monday, April 17, 2006

And now for something completely different

I'm taking the basic or introductory course on operating systems which pretty much means reading about 600 pages of Tanenbaum's Modern Operating Systems and then going to the final exam.

Some of things in the book like solving the classical IPC (InterProcess Communication) problems using the different IPC primitives (semaphores, monitors etc.) that include writing pseudocode. I think I'll understand and remember them better by writing them down as blog entries with possibly illustrations.

This is pretty much straight from the book but if there are errors, feel free to correct them.

So I'll begin with the classical IPC problems.

First a little introduction to semaphores:

I'm not planning to explain everything, that's what the books are for, but problems in interprocess communication revolve around situations where simultaneously (well in the multiprogramming sense) running processes must not be allowed to for example access certain variables simultaneously.

Different primitives have been invented to answer these issues of mutual exclusion, race conditions and synchronization.

A semaphore is basically an integer variable that keeps track of sleeping processes.

If a semaphores value is 0, there are no pending wake-ups on it and conversely if it has a value larger than 0, there are processes sleeping on it.

A process can perform two operations on a semaphore:
- DOWN: The process checks if the semaphore has a value greater than zero.
- If the value was larger than zero, the value is decremented by one and the process can continue to do whatever it was going to do.
- If the value is zero, the process is forced to sleep on the semaphore.

- UP: The semaphore is incremented and if there were processes sleeping on it, one of them is allowed to wake up and perform it's pending DOWN and let it do what it was originally planning to.

They key point here is that the UP and DOWN operations are atomic, that is no other process can interfere during an UP or DOWN operation and alter the semaphore's value. This atomicity makes it possible to use semaphores in synchronization and avoiding race conditions.

The Producer-Consumer problem

One of the classic problems is the Producer-Consumer problem. It involves two processes that share a common, fixed-size buffer. The Producer inserts information into the buffer and the consumer takes information out of it.

The basic problem is what to do when
a) The producer wants to put information into a full buffer

b) The consumer wants to take information from an empty buffer

A simple idea is to have the producer / consumer go to sleep and wait for its counterpart to make room or fill the buffer and then have it wake the sleeping process. This can however lead to a race condition as follows:

There's a variable count that keeps track of the number of items in the buffer. The producer checks if it's less than N (the size of the buffer) and the consumer checks if it's greater than 0.

Since there is no protection on the count variable the following could happen:
- The buffer is full and the producer checks the count and finds out that it's N. Now since this is a multiprogramming system, the scheduler decides the producer process has ran long enough and gives the turn to the consumer.
- The consumer takes one item from the buffer. It's been code to check if it is actually making room to a previously full buffer which is now the case. This means there has to be a sleeping producer there. (Actually I'm not sure why this is presumed.. ?) Anyway the consumer then sends a wake-up signal which is lost because the producer hasn't actually went to sleep
yet.
- Now when producer runs again, it tests the value of count which it previously read to its local variable and finds it N even though there in reality is room in the buffer. So the Producer goes to sleep and the consumer keeps running until the buffer runs out. Now the producer also goes to sleep.
- We have a situation where both processes are asleep waiting for each other to wake them up which will never happen.

The problem is easily solved with semaphores. The book's example uses three of them: full for counting the number of used slots, empty for counting the empty slots and mutex for making sure there's only one process at the buffer at any given time.

The buffer is initially empty to the full-semaphore is initialized to 0, empty is N and mutex is 1. Semaphores that are initially 1 and used by processes to ensure mutual exclusion in critical areas are called mutexes or binary semaphores. If each process does a down on a mutex before entering its critical region and up just after leaving it, mutual exclusion
is guaranteed.

Here's the code for the producer-consumer with semaphores:

#define N 100 /* Size of the buffer */
typedef int semaphore;
semaphore mutex = 1;
semaphore empty = N;
semaphore full = 0;

void producer()
{
int item;

while (TRUE) {
item = produce_item(); /* generate an item */
down(&empty); /* make sure there is room in the buffer */
down(&mutex); /* enter critical region */
insert_item(item); /* insert the item */
up(&mutes); /* leave critical region */
up(&full); /* increment the count of full slots */
}
}

void consumer()
{
int item;

while (TRUE) {
down(&full); /* decrement full count making sure there's stuff*/
down(&mutex); /* enter critical region */
item = remove_item(); /* take item from the buffer */
up(&mutex); /* leave the critical region */
up(&empty); /* increase the number of empty slots */
consume_item(item); /* do whatever you want with the item */
}
}

The semaphores are used in two ways. The mutex for mutual exclusion and the empty/full semaphores to synchronize the processes in other words to stop the consumer from trying to take from an empty buffer and vice versa.

So there. That's enough for now. Coming soon: The Dining Philosophers.

Sources: Tanenbaum, A.S. (2001) Modern Operating Systems, 2nd ed. Upper Saddle River, New Jersey: Prentice Hall

Tuesday, April 04, 2006

It has been a while again

There's not much left of the Spring semester. Four or five weeks of normal lectures but the Easter break eats five school days from it which is nice. Then two weeks of final exams and it's over. I've been getting pretty fed up with this again. :) Always happens towards the end. Fortunately I have most of the course projects done now, the C programming project just needs some polishing and then it's finished. We had a pretty great team in that project, everyone understood each other and we got stuff done in record time.

I'm going to see Morrissey today as he's playing in Helsinki. I'm not really a fan, haven't listened to him or The Smiths much but what little I've heard, I mostly like.

Saturday, March 11, 2006

Yay, I got a job!

*does a stupid victory dance*

So I finally got a summer job that's actually related to computer science. Happy happy, joy joy! I was almost certain I'd get nothing CS related and was prepared to spend the summer mostly chilling out, maybe taking few summer classes but a couple of days ago I received an email telling that I'd actually been hired for the place I'd interviewed for some days ago. I haven't written about the interview but I didn't feel it went that well overall and was pretty sure I'd get turned down so it was quite a (happy) surprise to get a positive answer. I had to read the first sentence several times to realize they were taking me. :)

So I'll be coding user interfaces with Java this Summer. It might not sound like the coolest job ever but I'm really excited about finally getting work experience in my field of study.

Sunday, February 19, 2006

Sunday randomness

I don't like Sundays.. can't really relax or concentrate on anything, you just keep thinking about the new week that's about to begin. I guess it dates back to the elementary and high school times when I just plain hated school. And let's not even talk about the Sundays during the military service.

Now it's a bit different. I most definitely don't hate school, I don't love every subject, not even most of them at the moment and the early wake-ups suck but I guess they'll be worth it in the end whatever that is.

Still the Sundays are bad.

Two weeks before mid-term exams. I have four exams but I think only the software engineering one will be tough and we're allowed to try it two times with a week between the takes which is nice. Telecommunications won't be trivial but the course has been interesting and I feel I've understood the concepts pretty well, database systems has been pretty basic stuff so it won't be difficult and the midterm of Japanese 2 is just katakana practice.

So the semester will be half way done already and the Spring is coming, yay!! Nothing beats the feeling when you notice that the sun actually feels warm again, the snow and ice are starting to melt and the nature shows signs of life again.