473,598 Members | 3,409 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4141
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.progr amming,
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.progr amming, 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.c om/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.l earn.c-c++ faq:
http://www.raos.demon. uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.co m -- 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.progr amming,


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

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.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
4548
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 process starts is not especially important, but it must be complete within a small number of seconds. The operations I am performing do not take a long time (hundreds of milliseconds), but as each part of the process is complete, my worker thread...
1
340
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 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)?
7
5724
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. The problem is, that the function doesn't seem tothrow any exception when it runs out of space. What can I do about it? Piotrek
6
3256
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 work may not be completed before the event is triggered again I am trying to add critical sections round the producer & consumer parts of
13
1618
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 thread swap out between the two operations. - sort of the inverted function than for which the GIL
5
2804
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 other thread will modify the list while operations are running. However, I at the end of the critical section, I need to fire an OnChange type of event, publishing the changed list item as part of my custom EventArgs. I want to be certain that...
0
7991
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7902
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8395
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8050
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8265
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5438
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3898
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1504
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1250
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.