473,395 Members | 1,891 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,395 software developers and data experts.

threads without threads

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
Nov 14 '05 #1
4 1159
si*****@gmail.com scribbled the following:
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.


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

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
Nov 14 '05 #2
si*****@gmail.com wrote:
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

Nov 14 '05 #3

<si*****@gmail.com> wrote

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.
Nov 14 '05 #4
si*****@gmail.com wrote:
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.
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/
Nov 14 '05 #5

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

Similar topics

9
by: Nicolas Fleury | last post by:
Hi everyone, I just discovered, correct me if I'm wrong, that as long as a threading.Thread is running, its destructor will not be called, because it is referring to himself. So if I have...
11
by: Przemysław Różycki | last post by:
Hello, I have written some code, which creates many threads for each connection ('main connection'). The purpose of this code is to balance the load between several connections ('pipes'). The...
6
by: m | last post by:
Hello, I have an application that processes thousands of files each day. The filenames and various related file information is retrieved, related filenames are associate and placed in a linked...
22
by: Jeff Louie | last post by:
Well I wonder if my old brain can handle threading. Dose this code look reasonable. Regards, Jeff using System; using System.Diagnostics; using System.IO; using System.Threading;
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
10
by: Mark Denardo | last post by:
Hi, I have multi-threaded application that requires one particular thread (Non-Form based) to receive data from other threads. I know how to pass control to Form Threads, but I believe there's no...
10
by: cj | last post by:
I'm writing a TCP/IP server app that will have many simultaneous connections. The main thread listens for new connections and starts a thread to handle each requested connection. These are short...
7
by: Michael | last post by:
I'm writing an application that decodes a file containing binary records. Each record is a particular event type. Each record is translated into ASCII and then written to a file. Each file contains...
15
by: Bryce K. Nielsen | last post by:
I have an object that starts a thread to do a "process". One of the steps inside this thread launches 12 other threads via a Delegate.BeginInvoke to process. After these 12 threads are launched,...
18
by: Jon Slaughter | last post by:
"Instead of just waiting for its time slice to expire, a thread can block each time it initiates a time-consuming activity in another thread until the activity finishes. This is better than...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
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,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...

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.