POSIX threads workshop

Today was the final day of a 3-day workshop on POSIX threads (pthreads) and Network programming, organized at the Ettimadai (Coimbatore) campus of Amrita. The past three days were extremely useful for all of us. The session was taken by our beloved Adinarayanan sir, who, with his eloquence and clarity of subject gave really deep insights into what was happening inside the processor.

Now, to what I’ve learned during these 3 days.

1) We were introduced to the Intel 32-bit and 64-bit Architectures, and the underlying hardware. The importance of knowing the ISA (Instruction set architecture) on which we are working in.

A simple “objdump -d a.out” (without quotes) would give the various instructions that the processor “sees”. By going through them we would get an idea about how the stack is set up, and how function calls behave. That was really interesting to know. And we get to see these “nop” (no operations), which are instructions that are put in place to adjust the pipelining (the intel 32/64 Arch follows a 16 segment pipelining!!).

2) POSIX threads (pthreads)
Threads are a certain line of execution of a process. To quote the example given by sir – “Assume you are waiting in a queue at the railway station to book a ticket. And then your phone rings. What would you do? You will not wait till you book the ticket to pick up the phone.. Do you?”

That’s how important threading is. Threads, when compared to processes, are light-weight (they have shared code and data). The processors with Hyper-threading (HT technology) and SMP (symmetric multi processors) can greatly improve the responsiveness and effectiveness of our programs, if we use the threads wisely.

For e.g: We created a multi-forked (spawn new child processes) and multi-threaded programs and compared their timings. At first we couldn’t appreciate the importance of it, since there wasn’t any difference in the time taken (real, user and sys showed no difference when compared to the multi-forked version).
But then, on the second day, we created concurrent servers using both multi-threaded and multi-forked versions. Now, the reasons became more clearer, why we should be multi-threading !!

POSIX threads are one standardization to the threading (parallel programming) paradigm. There are others also, like the openMP.

I aimed this to be an introductory post on POSIX threads. I am thinking of creating a detailed post once I get back home. And also, few examples of parallelization will be uploaded at my bitbucket account (http://bitbucket.org/pprahul).


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s