2010-05-01

The end

I'm closing this blog until further, since I do not have much time to invest in writing coherent, meaningful posts. Longer, in-depth texts will from now on appear on my homepage at zvrba.net Commenting is disabled since a lot of spam has lately appeared.

2009-11-29

Finally!

On thursday, 2009-11-26, I have finally defended my PhD! I'll be starting on the new job on tuesday...

2009-11-12

Unpredictability of execution times

I have written an article on intrinsic randomness of modern CPUs that you can fetch here. Originally, I tried to publish it in LWN, but since I haven't heard from their editors in over a week, I'm publishing it this way.

2009-10-17

A tricky bug

Today I debugged a piece of code that looked like this:
printf("foobar\n");
if(fork() == 0)
exit(0);
When the program is run from the terminal, the output is as expected: a single line containing "foobar". However, when the output is sent to a pipe or redirected to a file, two lines appear in the output. (Actually, the problem was a bit more complicated: there were n fork() calls and there were exactly n additional copies of the output). After a bit of digging around and not finding any obvious fault, I asked about it on IRC.

It turned out that stdout is fully buffered when it is attached to a pipe or a file. What happened is that fork() duplicated also the internal I/O buffers, which got flushed after the child process exited, thus producing extra output. I solved the problem by inserting a fflush(NULL); statement before forking, which flushes buffers of all output streams.

2009-09-03

Foxit PDF reader -- no go

Today I tested the Foxit PDF reader, version 3.1, since many people recommend it as a faster and lighter-weight alternative to Acrobat Reader. Well, its performance is disappointing: opening a 3MB PDF with Foxit takes 2-3 seconds before the first page is displayed. Opening the same PDF with Acrobat Reader (version 9.1) displays the document with no delay at all. I attempted to open few other PDFs with Foxit, with the same result: annoying pause before I could view the document, but with Acrobat Reader showing the document immediately.

So long Foxit, Acrobat Reader is still my favorite PDF reader.

2009-08-19

Unexpected behavior of std::bitset in visual studio 2008

I was writing code for generating prime numbers up to 10^9 (one billion) by sieve of Erathosthenes. So I created a class containing a member of type std::bitset<1000000000> and created an instance of the sieve class within the main function (i.e., allocated on the stack).

When I ran the program, it crashed with stack overflow. Since VC in debug mode implements stack overflow checking, the stack trace was not very helpful -- the program crashes within the _chkstk function. But in my simple test program, the only possible cause of stack overflow could be the instance of the sieve class which contains the bitset member. After lowering the sive's limit to 1000, the program worked fine. It was kinda surprising to learn that std::bitset, unlike std::vector, internally uses an array instead of dynamically allocated storage. (I confirmed this conjecture also by reading the source code of in the corresponding header file.)

2009-08-02

OODraw align nonsense...

I've been drawing some diagrams and I attempted to align (center vertically) several objects using one object as the reference object that should not be moved. But OODraw does not offer such feature; what it does instead is to align the selected objects using their bounding box as the reference, which is completely useless. A workaround is to "protect" the size and position of the reference object and then invoke the align command... which are few unnecessary extra clicks here and there. Stupid, stupid, stupid program!

2009-05-17

Git's way to the thrashcan

I tried to use git-svn and git for a while, only to get fed up with it today and going back to just using subversion. The thing that pissed me off is that I did git rm on wrong files. With subversion, if you do svn revert before commit, the old copy of the file gets restored (and, of course, removal will not be scheduled for commit).

With git, git checkout should, in theory, do the same. Googling about the problem, I found a tip that I should use git reset. However, neither did that restore the accidentally deleted files. Finaly, I experimented a bit and found out that git reset --hard does the trick. Before experimenting, I did, of course, make a backup of the whole repository to another place.

Now, I'm going back to subversion, which is much more intuitive to use. My work is too valuable to be stored in version control system with which I must experiment to achieve even the simplest of operatons. Yes, I found the --hard option in the documentation, but its explanation was so opaque that I wasn't sure whether it would achieve what I wanted.

Next time I'll be wanting to use a DVCS, I'll use Mercurial, as before.

2009-04-13

The meaningless school...

Now, midst in the financial crisis, I've gotten interested in how the economy works in general. Like, the stock market, how can perpetual economic growth be sustainable (in the long run it's exponential), etc. I would also like to know about things that are relevant for real life, like loan calculations, nominal and effective interest rates, forms of long-term savings, etc. And I know zilch about these things.

These things should be a part of basic high-school education. But no, we've been (and today's pupils are still being) overloaded with a bunch of meaningless historical and geographical facts that can be looked up in any online or offline encyclopedia. Among other meaningless stuff that is mostly irrelevant for the practical side of living in the modern world.

Currently I'm busy with writing my PhD, but first priorities on my reading list (after having finished the PhD) are introductory books in macroeconomy, capitalism, and game theory.

2009-01-04

Win32 threading API anomaly

I like to split my code into a series of simple helper functions. When developing for multithreaded environment, some of these functions have to be called while a certain mutex is held by the current thread. In POSIX, it's easy to test for a weaker condition, namely that the mutex is locked:

assert(pthread_mutex_trylock(&mtx) == EBUSY)

There is no way to check that the current thread holds the mutex. However, if another thread has locked the mutex, one may hope that pthread_mutex_unlock will return EPERM error code (I don't think that the pthread library is obliged to check for every possible error condition).

Take Win32, and the TryEnterCriticalSection function which returns, according to the documentation: "If the critical section is successfully entered or the current thread already owns the critical section, the return value is nonzero. If another thread already owns the critical section, the return value is zero."

Since I actually expect that the current thread already owns the mutex, the "or" clause in the first sentence makes it impossible to implement even the (weaker) sanity check which is possible under POSIX. Kinda shame.

2008-12-26

Visual Studio 2008, take 2

Recently I've been extensively working with multithreading in C++, with pthread API, so the code is not portable to Windows. Since I want to get some experience with Windows programming and Visual studio (my holiday project :)), I decided to try out Boost.Thread, which is a portable multi-threading library.

So I downloaded Boost 1.37, the bjam executable for NT, read through the boost getting started manual, compiled the necessary libraries in 32-bit and 64-bit mode as well as a small test application. The process has been surprisingly painless -- it took me about one hour from downloading bjam to having a working test application that comes along with Boost.Thread.

Another reason for wanting to have a portable application is that it is painful to develop over a remote connection to unix server. A compromise solution, which I've been practicing lately, is setting up shared folders with Virtualbox, editing the code with XEmacs, and compiling/testing in the virtual machine. This kinda works, but does not make the code portable :)

2008-12-05

New CSPIM release

I have released v1.0 of my CSPIM MIPS simulator. This release includes some previously outstanding issues, and the simulator can now simulate itself.

2008-11-29

CMake and assembly sources

I've been trying to figure out how to "nicely" integrate building assembler sources with CMake. After some digging around, I found a nice recipe recently posted to CMake mailing list:

set_property(SOURCE cputorture.s PROPERTY LANGUAGE C)

This works because the C compiler, at least on UNIX, recognizes .s as assembler source extension and invokes the proper assembler command.

2008-11-26

NetBSD 4 dissapointment

Well, I installed 32-bit NetBSD 4.0.1 in virtualbox. Then I attempted to install subversion through the pkgsrc system, and.. became thoroughly dissapointed. It pulled not only subversion, but also full apache (although it needs only the apache portable runtime, APR), perl 5.8, ruby 1.8, and who knows what else. I got tired of ruby compiling its "RI", whatever that is, and just deleted the VM. I think I'm going for some desktop ubuntu install now. Or maybe Fedora 10.

2008-11-12

Acrobat Reader 9 annoying accessibility feature

The annoying feature being accessibility which turns itself on, and there's no option to turn it off. Sure, there are a bunch of accessibility preferences, but no "disable" option. So every time I opened a document, I got an annoying dialog that the "document is being prepared...".

Solution: find "Accessibility.api" and "ReadOutLoud.api" files in Acrobat's installation directory (under plugins) and rename them to something else. I have created directory named "disabled" and moved the files there. Works like a charm.

2008-11-08

R

Recently, I had to process and plot a significant amount of data. Previously, I used to use gnuplot for that, but I've discovered two shortcomings: 1) gnuplot has limited data manipulation facilities, so I had to do data processing with perl scripts, 2) it has very arcane syntax and it's rather hard to make it do what you want, especially when you have slightly complex requirements (eg. bar charts of several nested data sets).

I have resisted learning R for a long time, because it also uses a rather arcane language with many complex and rather badly documented data structures. However, a week ago, I remembered my last experience with gnuplot, and I gave R a try. I'm glad I did even though it took me some time to get used to its data manipulation capabilities since the learning curve is rather steep. However, once you get used to it, it's so much easier and faster to manipulate data than with custom-made scripts, and much simpler to produce well-looking plots. Visit its homepage and take a look.

2008-10-06

Windows Vista and Visual Studio

I've bought a new laptop, got 64-bit Vista business with it, so I said - heck, let's give it a try. After one month of using Vista, I don't miss linux desktop at all. I have power management that works all of the time (and that locks the screen after wakeup, without any special configuration!), Flash that does not crash at least once a day (crash on linux manifested most often in the flash plugin eating 100% of CPU), sound system and mixing which works out of the box (no need for mysterious sound daemons that will enable multiple sound applications running simultaneously), plus availability of software for gadgets (garmin gps, nokia phone). I have even found a nice and free virtual desktop manager (VirtuaWin). One month after using Vista.. I won't be installing linux on the laptop anytime soon :-)

You have probably heard that User Access Control (UAC) is PITA, and there are a bunch of cookbooks on the net instructing on how to disable it. Coming from UNIX background, I find it rather natural that you have to type in admin password before performing system-critical tasks. Suggesting to people that they turn off UAC is rather irresponsible, and I have not done it. I like being warned when some operation requires elevated privileges. Oh, and I have turned off the sidebar - gadgets there are mostly useless and they just increase the startup time (which is, I must say, rather decent).

I have found replacement for all of the tools that I used under linux, except one -- development tools. And now, my comparison standard is not linux, but Solaris, with Sun's native developmet tools, CMake and dbx. (BTW, Solaris dbx just rocks! gdb is a poor match for it.) I have installed Visual Studio 8 Professional (I have free license through MSDNAA), and it has several shortcomings in comparison with Solaris tools.

First, I've heard many windows developers say that VS debugger is one of the best, but I find it rather mediocre compared to dbx. VS debugger does not recognize C++ overloaded iterators (so you can't persuade it to show you *it where it is some C++ iterator class) and it is a pain to display deeply nested data structure (just print -r in dbx). VS has even its own embedded command-line interface, but nothing indicates that these features are available through it. Sure, VS debugger is nice for single-stepping through the code, but this is not the way I usually debug the code. (What usually happens in my debugging session is that some assertion/check triggers a crash, I inspect the core dump, put a breakpoint near the offending place, and quickly print few variable values.) On the upside, the VS debugger understands STL containers and can display them in a nice form. But I'd go for dbx any day, only if it were available for Windows.

Oh yes, changing command-line arguments through IDE for debugged programs is PITA :-) If I run the program from the shell and it crashes, it takes several seconds to drop into the debugger, which is kinda annoying.

Another complaint is that VS does not seem to come with a decent profiler such as gprof on Solaris. Most people recommend to use Intel VTune, which costs money. Sun has recently released (free!) SPOT tool which produces a nice report of hot-spots over several runs of your program, in the form of cross-linked HTML pages and graphs.

Then there's DTrace which is currently unique to Solaris and some BSD variants (OS X, FreeBSD?).

Lastly, project configuration management is easier with CMake. I have not yet figured out how I can persuade VS to inherit project properties from the master "solution" properties. Given that projects have parent projects, I should probably play with a deeper project hierarchy. (But why can't I set master settings in the "solution"?! Bleh.)

IntelliSense is nice, but.. it doesn't work all of the time (I see rather often a message in the status bar that IntelliSense couldn't find a completion.. ). Though, when it does work, it sometimes saves me a lookup of member name.

In conclusion - Vista is a rather nice environment for everyday work and it is very stable. However, Microsoft's C and C++ development tools are no match to Solaris's tools, at least when it comes to lower-level stuff. (Maybe not so surprising, UNIX is traditionally C and C++ oriented environment, while MS is moving towards .NET). I'm definitely somewhat less efficient in development with VS (though not drastically); I don't know (yet) whether this is because I haven't learned all the features, or because Solaris tools simply are superior and have no match in functionality in VS.

2008-09-21

New site

You might want to literally waste some time on my new website: riddleschannel.org. The purpose of this page is to conduct certain experiments. If you want to help, just spread around the link!

2008-08-17

New code release: ext2frag

A master student of mine has developed a FUSE filesystem as a part of his master thesis. He needed to compare several fragmentation metrics of his own FS with that of EXT2. However, no decent programs for calculating EXT2 fragmentation statistics are available, so I set out to code one since the student was really short on time. You can get the program here.

2008-07-19

Free society ; some tips

I've recently watched Lessig's presentation on free culture.  It has been recommended to me as an example of interesting use of slides, but it is also an excellent lecture on how copyright stifles innovation and development.  The following is the basis for the whole lecture:

  1. Creativity and innovation always builds on the past.
  2. The past always tries to control the creativity that builds on it.
  3. Free societies enable the future by limiting the past.
  4. Ours is less and less a free society.

There's another noteworthy quote (by JC Watts, a US congressman/senator?): "If you're explaining, you're losing."

Regarding tips: perl's CPAN shell is an excellent tool to install packages and their dependencies. However, it uses active FTP by default which is more and more dysfunctional because of firewalls.  Exporting the environment variable FTP_PASSIVE=1 before running will make it use passive FTP.