Sunday, January 8, 2012

What is python Global Interpreter Lock (GIL) ?


Recently, while inspecting latest python library improvements at v3.0; i stumbled into the Global Interpreter Lock ( aka GIL );

The GIL is being utilized by CPython (C implementation of Python language) in order to synchronize multiple threads access to python bytecode; consequently resulting into only one native thread capable of executing python bytecode.
Apparently this limitation isn't common for all python implementations out there, for example, Jython (Java implementation of Python) and ironPython (.NET implementation of python) don't suffer from this issue.
The GIL is coming to prevent inconsistency which might happen when multiple native threads access the same interpreted code; it's that bad that i can result in erroneous object reference count update when multiple threads are trying to access the same python object.
The REALLY bad news is that the GIL lock is a single lock per interpreter! which means, that even in the case of a multi-threaded app with multiple threads trying to access different objects; all these accesses will finally have to be serialized, since they are going to share the same access LOCK for the different objects.
Consequently, the only way to have multiple locks is going to be by lunching multiple instances of the interpreter.
I have to admit that i was lying a little bit when saying that all threads accesses are gonna be serialized; that reason is that CPython interpreter implementation is doing more in order to mitigate the GIL problem. Whenever the lock is acquire by some thread, the interpreter will try to reschedule other native thread which doesn't need to access the GIL, like a thread which is about to execute an I/O operation.
From one point of view, this might be problematic, since I/O operations are being suddenly priorities upon cpu operations; however, on the the hand, this can be really useful and effective in case of multi-threaded app which is mainly doing I/O processing.

In the next post i am going to evaluate how bad is the GIL for parallel apps and what can be done to avoid it.

Thursday, September 9, 2010


Almost everyone of us have the chance to access different computers during his day; first the computer at the office or the university, the home computer, your laptop and maybe a friend's computer. Each time it happens you are sitting in in front of a computer which isn't you're private one, you will will find your self very quickly digging in the machine program files, trying to find your favorite apps and in case they are not installed then you will have to install them your self, not mentioning the overhead bound in such thing, from licensing issue to technical/time issues.

Me myself, had to grow weary of this thing very quickly. So i came up with an alternative idea; why not taking my OS/environment with all the tools office/games/E-mail client on a USB stick which i just hold in my pocket and pull out immediately when in happen to sit in front of a new system.

Just plug-in my USB stick and my system comes up very quickly, within about a minute, fully functional and responsive; imitating exactly my personal computer system but with different hardware.


On this project i am already working with two friends of mine for already about 3 months; The actual funding we request will only cover the tools we will use, like a computer system and licenses for software we will need in the development.

This project will be hosted as a freeware for public use, without any self profit.

Thanks in advance
Rami

Thursday, May 20, 2010

Iphone: "Youtube cannot connect" after upgrade to 3.1.2 firmware

After upgrading my iphone to 3.1.2 firmware using blackr1n and unlocking the sim using blacksnow, my Youtube application stopped working, posting the message "Youtube cannot connect".

I tried several solutions i found on google, but nothing did work!
However, the following did work for me, as i hope it would for you too.
1. add new source to Cydia repositories http://cydia.pushfix.info
2. install "Youtube fix #1" package from this source

Good luck.

Sunday, December 27, 2009

How to memorize difference between little vs. big endian?

Finally i discovered how to memorize distinguishing between little/big endian notation!
Guess how? Just understand the terminology and interpretation comes automatically.

endian stands for "end" or start (beginning)

little endian -> "start/beginning is small", hence memory starts with little number (lsb)

big endian -> "start/beginning is big", hence memory starts with big number (msb)

Sunday, October 25, 2009

HowTo: Embedding Non-english subtitle into iphone videos



After more than 4 hours, finally I can successfully embed hebrew/arabic subtitles into my iphone videos. For a matter of fact, googling this has took me to many various areas of iphone / video encoding which is not really what i am looking for.

So here is a short brief for what you need to do in order to add subtitles for iphone videos:
The process works in two phases:
  • VirtualHub
    Adding subtitle to your video
  • MediaCoder
    Converting your avi file to mp4; playable by your iphone.
Full procedure:
  • Install required software:
    - VirtualDub
    - Vobsub plugin for virtualdub. (choose TextSub plugin during installation)
    - 'MediaCode ipod edition'
  • Run virtualDub and load u'r video file
  • Add "TestSub" filter to u'r session (Menu: Video->filters->Add)
  • Navigate to u'r subtitle in TextSub configuration menu and choose the required font under "styles"
  • Choose compression mode to be Mpeg4-Xvid.
  • Save file
  • Open MediaCoder and load the file u just saved
  • Choose iphone as target resolution
  • hit 'Start'
  • Done. :)
I decided not to post links to installation software since links might be broken with the time, and googling them is quite simple operation.


Goodluck :)

Monday, March 9, 2009

Mastering Linux shell

I've been looking around about how can i extract the size of each subfolder in the current directory.  The issue is that find works recursively by default, and this will cause calculating the size of each subdirectory recursively.

The solution is to limit find depth by the parameter "maxdepth":
> find . -type d -maxdepth 1 -exec du -sh '{}' \;

Sunday, February 10, 2008

Ski videos


Abed crash captured. This is still not one of his best fallings...
Well done abed!!!