Friday, February 11, 2011

Multi-threading and the problem of race conditions

So, this week was the week where we needed to deliver the first prototype of our third year project. Until Wednesday, everything was going smoothly, without any bug or issues. But, when came the time to actually try the light client (the part of the software that would allow us to chat using a PDA), nothing was working as intended and I started to panic. Gabriel Royer, one of my teammate helped me out by going through every issue one at a time.  I needed i was panicked, my only responsability was a failure!


After one hour, i had to leave for work but not everything was solved so, I told myself that i would stay the night if needed to solve all this. However, while i was working, 2 of my teammates continued to debug and were able to solve every problem, me panicking really helped nothing.


In the end,  the problem wasn't even entirely my fault! Imagine my reflief, when the next day they told me that the problem was actually race conditions in the network that caused the application to not behave as intended on the PDA while it worked just fine in the emulator

Tuesday, February 1, 2011

Multi-Platform development and preprocessing.

Yesterday, while working for our school's third year project, I came across a problem, the code we were going to use and compile for 2 C# platforms (Asp.net 3.5 compact and Asp.net 4.0 normal) wasn't compatible for both platform. It took a hard time to realize since our compilator was giving an error like:
"I was waiting for an argument of type System.Net.IPAdress[], but received an argument of type System.Net.IPAdress[C:\System32]"

It took a while to actually figure out what was the problem. As it turns out, it was because i was trying to include files compiled for a not-compact version of Asp.net. The fix?(thanks to Julien Gascon-Samson on this one) incorporate the source files in a new project that would compile for a compact .net version. Once we did that, we tried recompiling and realized, there is a lot of different stuff on the compact framework, and that's where the pre-processing directives came into play.

We added every part of code that caused problem in a different "Utilities" static class which would help us code different behaviors on different platforms. The part to do that was quite simple:

[code lang="csharp"]

#if !PocketPC
return (int)e.SocketErrorCode;
#else
return e.ErrorCode;
#endif
[/code]
After i found out about this, everything became much easier, i was able to continue on implementing the lightweight client. What is the lightweight client is the title for another post..maybe!