Blocking functions



 DEVELOP > c-Plus-Plus > Blocking functions

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "Koo"
Date: 20 Dec 2003 04:34:10 AM
Object: Blocking functions
How do you create your own blocking function?
Koo
.

User: "Mike Wahler"

Title: Re: Blocking functions 20 Dec 2003 01:23:38 PM
"Koo" <iostream_h@hotmail.com> wrote in message
news:32c6afe6.0312200234.26bb8868@posting.google.com...

How do you create your own blocking function?

Here, use mine.
void block()
{
for(;;)
}
-Mike
.

User: "EventHelix.com"

Title: Re: Blocking functions 20 Dec 2003 03:53:18 PM
Any function that invokes a blocking OS primitive is a blocking
function.
If you wish to write a function that will not return until
a specific condition is met, use blocking semaphore calls to
implement such a function.
Sandeep
--
http://www.EventHelix.com/EventStudio
EventStudio 2.0 - Go Beyond UML Use Case and Sequence Diagrams
.

User: "Deming He"

Title: Re: Blocking functions 20 Dec 2003 09:04:55 PM
Koo <iostream_h@hotmail.com> wrote in message
news:32c6afe6.0312200234.26bb8868@posting.google.com...

How do you create your own blocking function?

Koo

Here's the best
void blocking()
{
char ch;
cin>>ch;
}
.
User: "Koo"

Title: Re: Blocking functions 21 Dec 2003 04:22:07 AM
Well, all of you examples work but i need something that doesn't use
99% of my cup time. I need something that stop the program and wait
for something to happen. And it needs to be fast!
.
User: "Jeff Schwab"

Title: Re: Blocking functions 21 Dec 2003 10:12:59 AM
Koo wrote:

Well, all of you examples work but i need something that doesn't use
99% of my cup time. I need something that stop the program and wait
for something to happen. And it needs to be fast!

Deming's suggestion doesn't use 99% of your CPU time:
void blocking()
{
char ch;
cin>>ch;
}
If you happen to be blocking to wait for input, this is probably the way
to go. If you're blocking for something else, you probably need a
system call. In that case, check in a newsgroup specific to your
platform, and they probably will be able to help you right away.
-Jeff
.

User: "Anders Hybertz"

Title: Re: Blocking functions 21 Dec 2003 05:00:48 AM
Koo wrote:

Well, all of you examples work but i need something that doesn't use
99% of my cup time. I need something that stop the program and wait
for something to happen. And it needs to be fast!

Have a look at www.boost.org and the condition class in the threading
library. It's a non-busy-wait blocking pattern that works very well.
If you are on Windows there are things like WaitForSingleObject that you
could use directly, but that is not platform portable - so I recommend
boost http://www.boost.org/libs/thread/doc/condition.html.
o<|:) /Anders
.
User: "Andy"

Title: Re: Blocking functions 21 Dec 2003 11:39:20 AM
Anders Hybertz <anders@hybertz.dk> wrote in message news:<A3fFb.63023$jf4.3718309@news000.worldonline.dk>...

Koo wrote:

Well, all of you examples work but i need something that doesn't use
99% of my cup time. I need something that stop the program and wait
for something to happen. And it needs to be fast!


Have a look at www.boost.org and the condition class in the threading
library. It's a non-busy-wait blocking pattern that works very well.

That was a useful tip. Not as clever as while(1), for(;;) and cin>>ch; though.


If you are on Windows there are things like WaitForSingleObject that you
could use directly, but that is not platform portable - so I recommend
boost http://www.boost.org/libs/thread/doc/condition.html.

o<|:) /Anders

.




User: "Jeff Schwab"

Title: Re: Blocking functions 20 Dec 2003 08:42:57 AM
Koo wrote:

How do you create your own blocking function?

That's a system call, not part of the language.
The function often looks like this:
#include <unistd.h>
unsigned int sleep(unsigned int seconds);
-Jeff
.
User: "Jack Klein"

Title: Re: Blocking functions 20 Dec 2003 12:00:02 PM
On Sat, 20 Dec 2003 09:42:57 -0500, Jeff Schwab <jeffplus@comcast.net>
wrote in comp.lang.c++:

Koo wrote:

How do you create your own blocking function?


That's a system call, not part of the language.

The function often looks like this:

#include <unistd.h>

unsigned int sleep(unsigned int seconds);

-Jeff

Nonsense, you can write a blocking function in perfectly standard C++.
void blocking_function(void)
{
while(1);
}
....blocks extremely well.
Unblocking is another issue.
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
.



  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER