threads without threads

S

sindica

Hello,

I have a counter loop which actually executes in a different thread.
The thread is there to check for a connection time out. However due to
some limitations, I cannot use pthreads or any OS dependant components
(my code should run on both windows and linux). I have to relegiously
stick on to ANSIC standard. Does ANSI C provide any inherent function
which could accomplish what I intend to do. Or putting it otherway,
how can I just deviate from my direct execution path and just return
to it after a stipulated time has elapsed.

~saraca
 
J

Joona I Palaste

(e-mail address removed) scribbled the following:
I have a counter loop which actually executes in a different thread.
The thread is there to check for a connection time out. However due to
some limitations, I cannot use pthreads or any OS dependant components
(my code should run on both windows and linux). I have to relegiously
stick on to ANSIC standard. Does ANSI C provide any inherent function
which could accomplish what I intend to do. Or putting it otherway,
how can I just deviate from my direct execution path and just return
to it after a stipulated time has elapsed.

ANSI C provides no thread support of any kind at all. As far as ANSI C
is concerned, the world is a single thread.
 
T

Thomas Matthews

Hello,

I have a counter loop which actually executes in a different thread.
The thread is there to check for a connection time out. However due to
some limitations, I cannot use pthreads or any OS dependant components
(my code should run on both windows and linux). I have to relegiously
stick on to ANSIC standard. Does ANSI C provide any inherent function
which could accomplish what I intend to do. Or putting it otherway,
how can I just deviate from my direct execution path and just return
to it after a stipulated time has elapsed.

~saraca

As far as sleeping goes, there is no support for task suspension
in the ANSI C language.

However, you _could_ write a wrapper function for your platform
specific code. Just supply different implementations based upon
the platform. This is what many cross platform project do.

--
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.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
 
M

Malcolm

I have a counter loop which actually executes in a different thread.
The thread is there to check for a connection time out. However due to
some limitations, I cannot use pthreads or any OS dependant components
(my code should run on both windows and linux). I have to relegiously
stick on to ANSIC standard. Does ANSI C provide any inherent function
which could accomplish what I intend to do. Or putting it otherway,
how can I just deviate from my direct execution path and just return
to it after a stipulated time has elapsed.
You need to rewrite the code. If you are executing a long function which may
need to abort (eg for connection time out) then pass in a callback function,
which gets called every so often, and which returns a trigger if the
function is to immediately abort. The callback can check the clock.
 
W

William Ahern

I have a counter loop which actually executes in a different thread.
The thread is there to check for a connection time out. However due to
some limitations, I cannot use pthreads or any OS dependant components
(my code should run on both windows and linux). I have to relegiously
stick on to ANSIC standard.

If it's only Windows and platforms w/ POSIX threads (including Linux), then
this might help:

http://sources.redhat.com/pthreads-win32/
Does ANSI C provide any inherent function which could accomplish what I
intend to do. Or putting it otherway, how can I just deviate from my
direct execution path and just return to it after a stipulated time has
elapsed.

Not in ISO C, though I strongly suspect that if you're blocked on a
"connect" that you're already using another set of interfaces. In that case
the right answer for this particular problem couldn't be in ISO C, and
trying to stick too closely to ISO--within the scope of this particular
problem--will probably create more problems than benefits.

When it comes to networking, the next level up in standards is POSIX. You
can generally find POSIX interfaces for Windows (as in the above example).
Ultimately you could always bundle cygwin.dll with your application:

http://www.cygwin.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

volatile and multiple threads 10
VLAs with threads 7
Interrupting Threads without Exception 5
max time threads 6
perl threads 2
threads and GUIs 18
Ruby & Threads 3
Green Threads - I want them to thrash... 5

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top