LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 05-13-2010, 05:30 AM   #1
sinu_nayak2001
Member
 
Registered: Oct 2009
Location: India
Distribution: Puppy Linux, Wary 530.
Posts: 31

Rep: Reputation: 20
Fairness: Where can it be better handled?


Hi,

I would like to share one of my practical experience with multiprogramming here.

Yesterday I had written a multiprogram. Modifications to sharable resources were put under critical sections protected by P(mutex) and V(mutex) and those critical section code were put in a common library. The library will be used by concurrent applications (of my own).

I had three applications that will use the common code from library and do their stuff independently.

my library
---------
work_on_shared_resource
{
P(mutex)
get_shared_resource
work_with_it
V(mutex)
}

my application
-----------
application1
{
*[
work_on_shared_resource
do_something_else_non_ctitical
]
}


application2
{
*[
work_on_shared_resource
do_something_else_non_ctitical
]
}


application3
{
*[
work_on_shared_resource
]
}

*[...] denote a loop.
------------


I had to run the applications on Linux OS. I had a thought in my mind, hanging over years, that, OS shall schedule all the processes running under him with all fairness. In other words, it will give all the processes, their pie of resource-usage equally well.

When first two applications were put to work, they run perfectly well without deadlock. But when the third application started running, always the third one got the resources, but since it is not doing anything in its non-critical region, it gets the shared resource more often when other tasks are doing something else. So the other two applications were found almost totally halted. When the third application got terminated forcefully, the previous two applications resumed their work as before.

I think, this is a case of starvation, first two applications had to starve.

Now how can we ensure fairness?

Now I started believing that OS scheduler is innocent and blind. It depends upon who won the race; he got the largest pie of CPU and resource.

Shall we attempt to ensure fairness of resource users in the critical-section code in library?

Or shall we leave it up to the applications to ensure fairness by being liberal, not greedy?

To my knowledge, adding code to ensure fairness to the common library shall be an overwhelming task. On the other hand, believing on the applications will also never ensure 100% fairness. The application which does a very little task after working with shared resources shall win the race where as the application which does heavy processing after their work with shared resources shall always starve.

What is the best practice in this case? Where we ensure fairness and how?

Sincerely,
Srinivas Nayak
 
Old 05-14-2010, 12:56 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 729Reputation: 729Reputation: 729Reputation: 729Reputation: 729Reputation: 729Reputation: 729
Moved to programming....

Note: Just skimming, it is not obvious to me what you mean by "fairness". Maybe something is getting lost in translation?
 
Old 05-14-2010, 01:30 AM   #3
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by sinu_nayak2001 View Post
...
Now I started believing that OS scheduler is innocent and blind. It depends upon who won the race; he got the largest pie of CPU and resource.
...
Suppose you have an application with the following piece of code:

Code:
...
// silly delay loop, _never_ use in multi tasking OS !

unsigned ctr;

for(ctr = 1000000; ctr != 0; ctr--)
  {
  // do nothing
  }
...
From your point of view the application is doing nothing useful, from the scheduler point of view the application is getting its fair share of resources - the scheduler knows nothing that the loop is useless.

Since the above mentioned resources are given to an application doing from your point of view nothing, the application that from your point of view are doing something useful are short of the needed resources.

So, maybe you have a situation like this ?
 
Old 05-14-2010, 02:54 AM   #4
posixculprit
Member
 
Registered: May 2010
Posts: 136

Rep: Reputation: 42
I would not modify the library code. work_on_shared_resource should do exactly what its name indicates, and do so without forcing any "fairness" algorithm on applications which use it. I'd either force application #3 to sleep after the call to work_on_shared_resource has returned (the programmer solution) or give applications #1 and #2 higher priorities than application #3, via the nice utility or similar (the system administrator solution).
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how is initrd handled during the boot Cazed Linux - Newbie 3 09-24-2008 07:23 AM
LXer: Linux: CFS Group Level Fairness LXer Syndicated Linux News 0 05-24-2007 10:31 PM
how are kernel updates handled? nick623 Ubuntu 8 03-16-2007 10:45 PM
Logs - how are they handled TL_CLD Slackware 2 09-15-2006 04:43 PM
How well is FAT32 handled? GAWd Linux - Newbie 3 12-13-2003 06:38 PM


All times are GMT -5. The time now is 11:44 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration