473,407 Members | 2,326 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,407 software developers and data experts.

Two functions running at once.

58
Is it possible for a C/C++ program to have 2 functions running at once? For example, the program holds a for() loop while it moves onto another function?
Jul 4 '08 #1
4 3700
Banfa
9,065 Expert Mod 8TB
If you mean multi-tasking then yes but this is not a feature of C or C++ but rather the platform/OS on which it is being used.
Jul 4 '08 #2
JosAH
11,448 Expert 8TB
Google for "pthread" (or "POSIX thread"). It's a multi threading library and I bet
a port also exists for MS Windows. It has everything you want.

kind regards,

Jos
Jul 4 '08 #3
Banfa
9,065 Expert Mod 8TB
On Windows look up Fibers or threads. Fibers are not a fully fledged threads and have to be manually scheduled and share thread data with other fibers in the same thread. A Thread is a separate execution process automatically scheduled by the system.

Read This
Jul 4 '08 #4
weaknessforcats
9,208 Expert Mod 8TB
C++ cannot have two functions running at once.

All C++ functions run sequentially, one at a time.

Now that's not to say that your C++ program won't be making operating system calls to spawn additional threads, fibers, or whatever. However, even in this case there is no concurrency UNLESS your machine has multiple processors or, lately, multiple cores.

Where there is one processor, only one thread can be active at a time. The others are blocked. Your code pretends there is concurrency and you have to program as though there were concurrency but there really isn't any.
Jul 5 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Dimension7 | last post by:
All, I am comparing to functions to see which is "better". In better, I mean more efficient, optimize, faster, etc. I have read other posts from other boards, but I'm not really sure of the...
2
by: Michael Schmitt | last post by:
Hello. What is the usual way for running functions in parallel on a multiple-processor machine. Actually I want to run a single computationally expensive function with different parameter sets....
17
by: Bart Nessux | last post by:
I understand that most people write functions to reuse code, no? So, I assume it would be better to write functions that are very specific, as opposed to those that are more generic. However, I...
2
by: Wenjie | last post by:
Hello, I read someone posted assertions that even the (public) member function is not static, there are probably only one copy of the code in the executable. Then except the...
1
by: Peran | last post by:
If I create a simple xslt stylesheet I can quickly test this in VS2005 by pressing the "Show XSLT Output" button rather than running the whole solution. If I then create a xslt stylesheet with...
8
by: Glenn | last post by:
Searching the "How Do I.." pages.. I don't see anything about functions like classic C/C++. If I want to do even a one-time operation, I _have_ to create a class? Seems weird to have to define an...
4
by: ahagley | last post by:
The problem: 1) I'm not a programmer, most of the time I'm a physicist, but I do numerical simulation. 2) I have a DLL that I want to use functions from. I have the .h file associated with the...
7
by: Immortal Nephi | last post by:
My project grows large when I put too many member functions into one class. The header file and source code file will have approximately 50,000 lines when one class contains thousand member...
9
by: Dahak | last post by:
I'm trying to generate dynamic functions to use as separate callbacks for an AJAX API call. The API doesn't seem to allow for the inclusion of any parameters in the callback, so I can't...
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: 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
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
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,...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.