Monday, September 15, 2014

A simple read-write lock implementation - Problem 2

This is the continued analysis of simple read-write lock implementation problem. This time it is starvation of writer locks.

Let me modify the thread routines and remove the sleep() after unlock, which means that readers or writers are assumed to have no pause in between. Here are modified thread routines.

void*
thread_routine1 (void *arg)
{
    for (;;) {
        my_rwlock_read_lock(&g_rw_lock);
        printf("Grabbed read-lock -- 1\n");
        sleep(10);
        my_rwlock_read_unlock(&g_rw_lock);
    }
}

void*
thread_routine2 (void *arg)
{
    for (;;) {
        my_rwlock_read_lock(&g_rw_lock);
        printf("Grabbed read-lock -- 2\n");
        sleep(10);
        my_rwlock_read_unlock(&g_rw_lock);
    }
}


void*
thread_routine3 (void *arg)
{
    for (;;) {
        my_rwlock_write_lock(&g_rw_lock);
        printf("Grabbed write-lock -- 1\n");
        sleep(5);
        my_rwlock_write_unlock(&g_rw_lock);
    }
}

void*
thread_routine4 (void *arg)
{
    for (;;) {
        my_rwlock_write_lock(&g_rw_lock);
        printf("Grabbed write-lock -- 2\n");
        sleep(5);
        my_rwlock_write_unlock(&g_rw_lock);
    }
}


What is the output?

Grabbed read-lock -- 1
Grabbed read-lock -- 2
Grabbed read-lock -- 2
Grabbed read-lock -- 1
Grabbed read-lock -- 2
Grabbed read-lock -- 1
Grabbed read-lock -- 1
Grabbed read-lock -- 2


:). As you see the writers are severely starved! As of now, I am not still have zero thoughts to fix this issue. If you find any suitable approach please let me know in the comment box.

Wednesday, September 3, 2014

Filesplitter source in github now!

Today, I am glad to announce the availability of FileSplitter source code in github. This was lying in sourceforge for quite sometime and now I wish to enhance my github profile and uploaded the same to github :). This was written way back in 2007 (IIRC) and is written in Java. The UI design matches with that of chainsaw file splitter (check here). The UI is written using Java Swing APIs. Unfortunately, this works only with windows i.e. final output is batch file and cannot be used in Linux :(. I have enhancement plans for the same and willing to improve it in future releases. There are lots of known bugs and I wish someone could pull up more bugs to make it robust. Also the code is little bit cluttered and want to cleanse the same. For everything, I need to find sufficient time to move ahead. The second good news is that the code is available under GNU GPL license and you are free to enhance it and play with it.

Jump to the github page now!: https://github.com/nkumar85/filesplitter_java

Features
--------------
Can handle files above 4GB and split sizes above 4GB (need confirmation)
Checksum validation tool available to check if the merged file is in tact.

Planned enhancements
-------------------------------
Shell script support for Linux
Tool to merge the split files manually
cleanse cluttered code

Bugs
---------
long strings are not taken care for creating batch files
Lot more bugs which I have not documented [There are no show stoppers though ;)]

Note
--------
The code is provided under GNU GPL License and does not contain any proprietary code/materials in it. Please do not sell the tool for money. Feel free to distribute amongst anyone for free of charge. Any modifications to code has to be informed to me (email details are provided in the About dialog of filesplitter)

Enjoy using the filesplitter :)