semaphore mutex = 1; // Controls access to the reader count
semaphore db = 1; // Controls access to the database
int rdrCount; // The number of reading processes
public void Reader()
{
while (true) // loop forever
{
Wait(mutex); // gain access to rdrCount
rdrCount = rdrCount + 1; // increment the rdrCount
if (rdrCount == 1)
Wait(db); // if this is the first process to read the database,
// a Wait on db is executed to prevent access to the database by a Writer
Signal(mutex); // allow other processes to access rdrCount
read_db(); // read the database
Wait(mutex); // gain access to rdrCount
rdrCount = rdrCount - 1; // decrement rdrCount
if (rdrCount == 0)
Signal(db); // if there are no more processes reading from database, allow Writer
Signal(mutex); // allow other processes to access rdrCountuse_data();
// use the data read from the database (non-critical)
}
}
public void Writer()
{
while (true)
{ // loop forever
create_data(); // create data to enter into database (non-critical)
Wait(db); // gain access to the database
write_db(); // write information to the database
Signal(db); // release exclusive access to the database
}
}
Subscribe to:
Post Comments (Atom)
Pageviews last month
Labels
.Net
(1)
.Net interview questions
(1)
AlternatingRows
(1)
AlternationCount
(1)
AlternationIndex
(1)
Brushes
(2)
C#
(4)
Checking for already opened window
(1)
Constructors in C#
(1)
Contructor
(1)
Convert()
(1)
ConvertBack().
(1)
Converters
(1)
DataBinding
(2)
DataGrid
(1)
DownloadStringCompleted
(1)
Entity Framework
(1)
Graphics.
(1)
ImageBrush
(1)
interface
(1)
ItemsControl
(1)
IValueConverter
(1)
LinearGradientBrush
(1)
LINQ
(1)
Parametrized Contructor
(1)
RadialGradientBrush
(1)
Reading Xml in Silverlight Xap
(1)
Silverlight
(1)
SolidColorBrush
(1)
Style
(1)
Styles
(1)
The URI prefix is not recognized
(1)
user control
(1)
Value and Reference Types
(1)
ValueConverter
(1)
WebClient
(1)
WInform
(1)
WinForm interview question.
(1)
WPF
(6)
WPF ListBox Template DataBinding MVVM DataTemplate
(1)
WPF Silverlight ToolTip
(1)
WPF User Control
(1)
WPF usercontrol
(1)
0 comments:
Post a Comment