Website Logo

Created a new barik.net logo using Adobe Photoshop CS and the Silkscreen type family of fonts by Jason Kottke. The UNIX terminals were created by hacking up the 0x32 character code in the Microsoft Webdings font. The journal commenting system has also been re-written, though the changes are not visible from the users’ end. Responses toward the new logo thus far have been overwhelmingly positive.

And with the newest release of Firefox and its live bookmark feature, I’ve modified the journal code to return an RSS feed for almost every type of page. It also seemed like an opportune time to add a favorites icon, or favicon.ico with the help of the freeware utility png2ico. As usual, I fully expect Adam to follow suit and have a similar feature within the next few days. He always does.

The Cathedral and the Bazaar

So I didn’t get the job. But events like these do allow one to reflect, and I’m now more determined than ever to go and do something with my life. Here’s a good start:

  • Write about things that I learn, instead of things that I do. And yes, this means not necessarily writing an entry every single day of the week. It also means writing more about technical material.
  • Read more books about the area of interest that I’m pursuing. In short: algorithms, algorithms, algorithms.
  • To get more experience, I need to work with more open source projects. I’ve dabbled with several projects during these past few years, but only at the sidelines.

As they say, every moment is a chance to turn it all around. Here we go.

Java is pass-by-value

Too often I hear that languages such as C and Java have pass-by-reference by virtue of the fact that for objects and pointers, the address of the object is passed as a formal parameter rather than the object itself. Coming from a compilers background, this interpretation makes me cringe. What’s more amazing is that I continue to meet Java Architects and experienced programmers who throw around these definitions so informally. This misconception is further exasperated by authors like Bruce Eckel, who mutate the definitions in an attempt to simplify it. In Thinking in Java, Eckel admits this distortion of terms:

One could argue for the precision of such convoluted explanations, but I think my approach simplifies the understanding of the concept without hurting anything.

The fact of the matter is, the formal distinctions between pass-by-value and pass-by-reference are critical in fully understanding the intricacies of the language and why Java behaves exactly the way it does in certain contexts. Indeed, having nearly four years of experience teaching object-oriented programming, I’ve found that students who use the fuzzy definition, initially, have a clearer understanding of what’s going on but are hurt in the long run when using languages where the pass-by-reference mechanism is not so well abstracted. Even Eckel hints that his informal definitions work well for Java, but not necessarily for other true pass-by-reference languages:

There are those who say "clearly, it’s a pointer," but this presumes an underlying implementation. Also, Java references are much more akin to C++ references than pointers in their syntax. The language lawyers may claim that I’m lying to you, but I’ll say that I’m providing an appropriate abstraction.

In formal language theory, the definitions of pass-by-value and pass-by-reference are indeed more complicted, but not by much. I’ll use the definitions from Advanced Programming Language Design by Raphael A. Finkel to illustrate:

  • In pass-by-value, the value of the actual parameter is copied into the formal parameter at invocation. Value mode is the most common parameter- passing mode. Some languages, like C, provide only this mode.
  • The L-value of the formal parameter is set to the L-value of the actual parameter. In other words, the address of the formal parameter is the same as the address of the actual parameter. Any assignment to the formal parameter immediately affects the actual parameter. FORTRAN only has reference mode, and reference mode can be simuted in C through the use of pointers.

I think it’s time to get it straight. Java is strictly pass-by-value, even by Sun’s own admission. Yet, despite this evidence, something inside me tells me that I’m not quite right either. Perhaps Bruce Eckel said it best in the first edition of his text. What we really need is a new term: pass-by-handle.

Posted in Uncategorized | 1 Reply

Microsoft interview

Had a light breakfast at Bojangles’ for chicken biscuits and orange juice, followded a quick trip to the Overlook Building for an all day interview with Microsoft. It’s good to know that Microsoft no longer does riddles or puzzles, so the interview was largely technical and managerial in nature. Still, it seems that the questions were fairly rudimentary and don’t really illustrate the difficulties in true software development. In hindsight, one could probably go straight to Chris Sells’ website and simply memorize the questions from his list. Perhaps that’s what I should have done in the first place.

North Carolina is a beautiful area and I had a lot of great friends there. And regardless of what happens, I’m confident of my abilities as a programmer. I know it’s just a matter of time before I do something great.

Microsoft Itinerary

I’m flying up to Microsoft at RTP, and I thought I’d quickly share my itinerary with you. I’ll be leaving tomorrow from Atlanta to Releigh around four in the evening. The flight is about an hour and a half. During my two night stay in North Carolina, I’ll be at the WinGate Inn on Page Road.

My interview is at 11:30 on Monday and begins in Conference Room Raleigh 2005 in the Overlook Building, Suite 190. I spent the night preparing by carefully watching and taking notes on Antitrust. It’s not in the box, it’s in the band.

As of now, it also looks like I’m free both nights. If you’re in the area and want to hang out just give me a call. This means you, Stacie. Have a nice weekend everyone. Strength and honor.

Posted in Uncategorized | 1 Reply

Threads

In this article, I’ll use the POSIX Threads Library to provide an introduction to threads and its implementation in the Linux environment. I’ll also try to provide a good mix of application and introductory theory along the way. Chapter 4 of ALP will serve as the primary reference. This article is written more for me than anyone else, so it’s a bit terse in areas that I’m already familiar with.

Threads are somewhat like processes in that they are a mechanism to allow a program to do more than one thing concurrently at a more fine-grained level of execution. Conceptually, threads exist within a process, and unlike processes, these new threads share same memory space and resources as the original.

Threads are not part of the standard library. Instead, Linux implements the POSIX Threads Library. As a result, you must include the header file pthread.h and link your program with libpthread. Of course, POSIX threads are not the only thread implementation.

Like processes, each thread is identified by a thread type, pthread_t. Threads can be created using the pthread_create function, and there are restrictions on the parameters that a threaded function may accept. Threads can be joinable or detached. A joinable thread hangs around until pthread_join is called to obtain its return value; a detached thread automatically cleans itself up after it’s finished. An example of creating a thread might be:

pthread_t thread_id;
pthread_create (&thread_id, NULL,
   &my_function, NULL);

It is also possible for a thread to request that another thread be terminated. This is known as thread cancellation and is done using pthread_cancel. The effect of a cancellation request is dependent on the type of thread: whether it is asynchronously cancelable, synchronously cancelable (deferred), or uncancellable. Sychronous threads can be cancelled through the use of cancellation points, which can be set using pthread_testcancel. And for critical sections, cancellation can be disabled entirely, using pthread_setcancelstate.

Normally, threads share the same variables and memory space. But thread-specific data can be used to duplicate variables in each thread if necessary. These shared data items can not be accessed using normal mechanisms. Instead, use a pthread_key_t in conjunction with pthread_setspecific and pthread_getspecific.

Sometimes it’s also useful to clean up functions. In this case, a cleanup handler can be called when a thread exits. This is done using a stack-like discipline: pthread_cleanup_push and pthread_cleanup_pop. For instance, you may want to write a cleanup handler which frees memory managed by malloc. One way to do it might be:

pthread_cleanup_push (free, temp_buffer);
/* code which might cancel thread */
pthread_cleanup_pop (1);

As you can probably guess, programming with threads is tricky as it is. But the introduction of threads also introduces two major sources of bugs in our code: race conditions and deadlocks. To eliminate race conditions, we use mutual exclusion locks, or mutexes. This support is generally provided by the operating system, and can be used to block execution paths. Deadlocks require a bit more explanation.

A deadlock occurs when threads are blocked waiting on a state that will never occur. For example, if thread A mutex waits on thread B, and thread B mutex waits on thread A, a potential deadlock has occurred. In such a case, the type of mutex will determine if an actual deadlock occurs: a fast mutex (the default) will always deadlock, a recursive mutex will allow multiple locks, and an error-checking mutex will detect a deadlock and return EDEADLK.

While mutexes allow us to block on the variable level, we can also block on the thread level through the use of semaphore locks and condition variables. Semaphores are essentially atomic counters. Similarly, condition variables provide atomic ways to set and unset flags in threaded programs without resulting in race conditions. Condition variables can be declared using the pthread_cond_t type.

The question of whether to use threads is still a hotly debated topic. In general, programs will benefit from threads most when memory must be shared and tasks can be clearly parallelized.

Dad’s Garage

I dropped by Georgia Tech to run some errands and chat with a few friends and professors in the early afternoon. It’s a new month and Dad’s Garage once again has a new theme. This month it’s Information Overload, where the cast decides its next skit using images from every day information sources, like newspapers, magazines, and the always popular spam e-mail. Our numbers are dwindling.

Farscape

Started watching Farscape. It’s a pretty addictive series, and I’ve been interested in it ever since I visited the booth at DragonCon. I had forgotten how much television gets in the way of getting any real work done.

Dead Poets Society

The hard drive from New Egg came in today and was promptly installed on chronos. The machine now has a dedicated drive for Windows XP, and a shared FAT32 partition to transfer files between operating systems. Need to get back on track within the next few days.

Posted in Uncategorized | 1 Reply