473,383 Members | 1,795 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Critical Sections

Hi,
I am trying to learn Critical Sections. I have written a small
program. Source code problem below.

What the program is doing is disabling the CRTL-C signal in the
critical section. My problem is that when in the Critical Section I
press the CTRL-C signal more than once. As supposed nothing happens,
but when critical section ends, should it give me all the CTRL-C
signals pressed or just one (its giving me one)?

How should the exact implementation be?

I hope some one out there understands my problem.

Thanks in advance
/* Source Code */

#include <stdio.h>
#include <errno.h>
#include <signal.h>

int cnt;

void CTRL_C_Handler (int sig)
{
cnt++;
printf ("%d. Now we are in CTRL_C_Handler.\n", cnt);
(void) signal (SIGINT, CTRL_C_Handler);
} // end method CRTL_C_Handler

main()
{
system ("clear");

(void) signal (SIGINT, CTRL_C_Handler);
sigset_t masking;

cnt=0;
sigemptyset (&masking);
sigaddset (&masking, SIGINT);

if (sigprocmask (SIG_BLOCK, &masking, NULL) == -1)
printf ("An error encountered: %s.\n", strerror(errno));

printf ("Enterend in Critical Section. Last for 5 seconds.\n");
printf ("Pressing CTRL-C will be useless.\n");
sleep(5);

printf ("Critical Section is ending now.\n");
if (sigprocmask (SIG_UNBLOCK, &masking, NULL) == -1)
printf ("An error encountered: %s.\n", strerror(errno));

while(1); // infinite loop
} // end main
Nov 14 '05 #1
2 4125
Xarky wrote:
Hi,
I am trying to learn Critical Sections. I have written a small
program. Source code problem below.

[code snipped]

Sorry, but the _standard_ C language has no facilities or support
for Critical Sections so it is off-topic for this newsgroup.

However, a better newsgroup to discuss this is news:comp.programming,
as it is an advanced programming concept. Just remember that not
all computer systems in the world support Critical Sections. And
when you post to a newsgroup that isn't platform dependent, like
news:comp.lang.c and news:comp.programming, you are posting issues
that apply to all computer systems in the world (or most of them).

Followups set.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

Nov 14 '05 #2
In comp.lang.c Thomas Matthews <Th****************************@sbcglobal.net> wrote:

(xpost and followups ignored, since this is metatopical)
However, a better newsgroup to discuss this is news:comp.programming,


I would also suggest comp.unix.programmer, given the code that OP
posted.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Nov 14 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

77
by: Charles Law | last post by:
Hi guys I have a time critical process, running on a worker thread. By "time critical", I mean that certain parts of the process must be completed in a specific time frame. The time when the...
1
by: Xarky | last post by:
Hi, I am trying to learn Critical Sections. I have written a small program. Source code problem below. What the program is doing is disabling the CRTL-C signal in the critical section. My...
7
by: Piotrek Stachowicz | last post by:
Hi, I need to create the situation in my system, where no more critical sections can be initialized (win2000Server). I thought about creating a simple c# application and using the Monitor class....
6
by: MPH Computers | last post by:
Hi I am looking for some help on Threading and Critical Sections I have a main thread that controls an event the event handler creates a new thread for carrying out the work because the...
13
by: Hendrik van Rooyen | last post by:
Hi, I would like to do the following as one atomic operation: 1) Append an item to a list 2) Set a Boolean indicator It would be almost like getting and holding the GIL, to prevent a...
5
by: =?Utf-8?B?VmFubmk=?= | last post by:
Hi, I have a component where I need to have thread-safe access to a list. Operations on the list are done in critical sections (lock (lockObject) { ... } ) in the usual way, to make sure that no...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.