Sunday, October 20, 2013

A lesson in philosophy

It has been a while since there has been any forward progress made, mostly due to class eating up all of my time.  In order to not feel like the time has been completely wasted, I thought I'd make a post about a recent assignment I completed.

The assignment was to implement a solution to the famous dining philosopher's problem.  The problem generally requires students to use various tools such as semaphores and threads that, historically, have not been available in a simple cross platform way unless certain specialized libraries have been added.  Enter the C++11 standard, and you have the opportunity to finally write a cross platform solution with nothing but the STL.

The dining philosophers problem turns out to be one of the problems where it is beneficial to think of each thread as a class - after all, each thread represents a philosopher.  This solution called for a classic runnable class model which I implemented entirely in a header file out of a combination of laziness and ease of use (the latter reason is debatable).

The runnable class
A few points about the runnable class: first - visual studio hasn't yet implemented the delete operator so we still have to work to make runnable noncopyable the old way.  I expect this will change in the near future, so the preprocessor guards will come out eventually.  Everything else about this class is fairly straightforward - implementors are encouraged to use the m_stop variable or the stopped method inside their loops in order to respect the stop command, and I'm not sure if more can (or even should) be done on this front, though I am wary of relying on the people using the class to ensure most of the methods the base class itself defines are useful.

The magic of the solution occurs in the philosopher class.  C++11 provides a lock function that guarantees it is deadlock free.  A simple solution (modified Dijkstra's solution) is then presented using this mechanism for philosophers to request their chopsticks.

A simplified view of the philosopher class

C++11 provides a couple of interesting locking mechanics for a mutex, but the appropriate mechanism for a philosopher is a unique lock, since only one philosopher may hold a chopstick at any given time and the lock must hold even after the method that locks the resource (get_resource) has completed. The second argument to the unique_lock constructor tells it not to immediately grab the lock, since that will be done in the thread's run loop.

And that is really all there is to it.  Unfortunately, the current solution does nothing to address possible thread starvation.  In order to truly do that, a conductor would be needed (or in this case, a waiter).  The solution to that problem, however, will have to wait for another day.  Until then, you can click here to view the git repo for this project.

Saturday, August 24, 2013

Adventures in reinvention

If at first it seems right, that is no reason we can't try again, right?

It has been a while since I've made any forward momentum on the RDA, but I'd like this post to be the first step in picking things back up.  And since this is a new location for the development blog, I'll give some history - after all, that is the purpose of this blog.

From the beginning of this project I felt like I needed an outlet to speak about the development of the RDA  - design decisions and technical choices about the project are so numerous that I'd really like a way to keep track of them for myself even if no one else really reads this.  The plan was to post reasoning, updates, and even code snippets so that this would be a truly open project.  I do enjoy a bit of web design every now and then so I went ahead and made a GitHub page with the intention of keeping track of everything there.  It wasn't a bad system, but I always felt like it could be made better and never had any time to do so myself.

After some though, I realized that I should really stop trying to reinvent the wheel here and just start a blog on Blogger (which made sense since I've already set up the RDA dev email address).  So here we are - this should help me focus on finishing something resembling a product and encourage me to make more posts since updating the site will no longer be such a hassle.  I'll leave the old site up for historical reasons, but I'll be working on back porting the posts from it to here, so I won't have to jump back and forth.  Eventually, I will probably convert the GitHub site into something more static with a link to this blog.  I'll mark posts from the past and try to provide more information in the new spirit of this blog.

Now on to features: the RDA has a solid networking setup with Twisted and AMP currently, but what it is lacking is the ability to separate users into chat channels.  After some waffling, I'll be using a publish subscribe paradigm for the channels.

The bulk of the code will reside in the chat handler on the server.  For now, I'll focus on simply providing the ability to split users into channels - I'll provide the functionality to manage the channels later when I work on the concept of a campaign.

Sunday, January 27, 2013

Code conformity

Post from the past

Got to... style all over... python

Not much to this update - sorted out a few mistakes in git and finally purged all legacy urls. Submodule should be working correctly now. Overall this was mostly prep work for getting back into the swing of things.

Notes from the future

I had seriously broken everything and was quite happy when I made the corrections here.  As the post notes, the submodule structure was very wrong.  This was due to the fact that I had copied over a lot of the data (poorly) from the original BitBucket repo that house it.  As I will explain in an older post, I had chosen BitBucket mostly out of cowardice.  I wanted the ability to keep the repo private, but I eventually relented and moved to GitHub to run the original blog.  Half baked ideas from yours truly?  Say it ain't so!

Monday, August 13, 2012

Website updates!

Post from the past

Now with 100% less placeholders

I got a couple of complaints about the old style of the site so I consulted with a marketing coordiator I happen to live with and came up with both a new site and a logo for the RDA. The website still a work in progress, but it's slowly edging closer to being done and it is very exciting.

The original icon had the plug for the ethernet facing upwards, as you could probably see from the previous post. After thinking about it (and more consulting), the logo changed to what it is now. I really wanted the image to symbolize what this project is and I think the unmistakable symbol overlaid with an ethernet is a fairly good distillation of what this RDA does and is. I also wanted to subtly incorporate themes from the Twilight caste, and hopefully that comes through with the image as well. With that bit of work done, and the stabilization of not only the website but also the source control and Qt, I feel much better about moving on.

Sunday, August 12, 2012

Icon has cheezburger

Post from the past

RDA logo and icon in the works

In addition to a site overhaul, I've started work on the RDA logo. Inkscape is surprisingly easy to use and the learning experience has been fun so far. I hope to have it done soon so I can resume work on the actual RDA.



Also of note: Qt has been picked up by Digia, which is good news indeed. I look forward to the eventual release of Qt5!

Saturday, August 4, 2012

First blog entry

Post from the past

Not much to look at yet

Welcome to the RDA dev blog. In the following days, I'll be adding some old news to keep a complete history of development up to this point. They will have their own titles and I will try to set the date properly, but this is the real first post of the new site. I've taken a small break from coding (before I work on getting the Qt reactor working with Twisted) and I have been refreshing my memory on web dev. This project has really been teaching me things, it has been fun picking up some new tricks in CSS and HTML. My plan is to have the site in HTML 5.

This week turned up some troubling news as well. Apparently, Nokia has shut down their Australian offices which makes me worried about the future of QML. I was really looking forward to the beta release of Qt 5 and the new QML additions it would bring, but this seems to explain the delay. Not much to do except wait and see how things play out, I'm afraid.

Notes from the future

This was technically the first post of the old GitHub based dev blog.  Now that I'm using Blogger, hopefully I'll never have to backfill again!

Thursday, July 26, 2012

QTReactor meltdown

Post from the past

More fun with QT

So, more fun things. qtreactor has been removed from Twisted due to licensing issues and has not yet been replaced. This is a problem since both qt and twisted have calls that start their event handlers that are blocking. Good times. There seems to be a push to convert the old qtreactor to pyside, so I will see if I can use that as a stop gap for now.