473,624 Members | 2,117 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to make two simultaneously running infinite whiles in C?

2 New Member
How to make TWO simultaneously running infinite whiles in C?

If I do this in JAVA:
public static void main(String[] args)
{
new Thread(new Runnable()
{
@Override
public void run()
{
while (true)
{
// some code ...
}

}).start();

while (true)
{
// some code ...
}

}

or in PYTHON:
def thread():
while True:
# some code

def main():
tid = threading.Threa d(target = thread)
tid.start()

while True:
# some code

if __name__ == '__main__':
main()

all OK, but when I do this in C:
void *thread(void *args)
{
while (1)
{
// some code
}
}

int main()
{
pthread_t tid;

pthread_create( &tid, NULL, thread, NULL);
pthread_join(ti d, NULL);

while (1)
{
// some code
}

return 0;
}

only the loop in the thread runs and the compiler simply does not read the code after creating the thread..
Jun 21 '17 #1
1 1220
artnx
2 New Member
Found the problem:
You need to remove pthread_join (tid, NULL);
Jun 21 '17 #2

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

Similar topics

43
5572
by: Gremlin | last post by:
If you are not familiar with the halting problem, I will not go into it in detail but it states that it is impossible to write a program that can tell if a loop is infinite or not. This is a fallacy built on the assumption of mythical infinite all powerfull machines. In reality we deal with finite machines that are capable of two states in a loop, they either terminate, or repeat themselves. In the mythical halting problem scenario...
1
4369
by: rock72 | last post by:
Hello Everyone, Can anyone tell me how to create a running sum in query ? Days should be from 1st record 1, then 2nd record 2 and so on...... Thanks Tim --
6
2934
by: KashMarsh | last post by:
Trying to show running totals on a report, except it needs to show one total amount and values being subtracted from it. For example, the report shows a Total Inventory amount (TotInvAmt). And then amounts for each month for the orders like JanAmt, FebAmt, etc. I want to show under each month column the following: (TotInvAmt)-(JanAmt)=B ----result shows under the Jan column B-(FebAmt)=C ---------result shows under the Feb column...
1
2117
by: Larry | last post by:
Hi, my friends, As I know, service and start automatically even before user login. So If it's possible to create a service, make it running when system start , and record windows login password when a user login. Best reards, Larry
8
7300
by: Joe Abou Jaoude | last post by:
hi, I have a web app with forms authentication and a timeout session of 20 mins for security reasons. I recently added a feature that allows users (if they want to) to automatically log in (without entering username and password) using the cookies. Now in this case the 20 mins session timeout has no meaning anymore so I m thinking to make the timeout infinite in this case only. my question is, if i do this, and then a user used the...
0
1270
by: trembita | last post by:
I have to databases that I connected together using a UNION. That was not a problem. I now need to create a running total using all of the data within the UNION. I can make a running total that does one table or the other, the problem is when I try to create the running total on the UNION. The result is nothing close to correct running total. Is there an issue calculating a running total over a UNION?? Is there another way to do this?
6
3578
by: neeru29 | last post by:
I'm executing two function in a program in a infinite loop. In that loop i want run a particular a particular function which is out side the function, but that function also runs simultaneously with that function. when i tried with the threading.Timer(), the function that is to be executed, it throws an exception as cannot start another thread of that function. As that function is already running in the loop. Can u provide me the...
2
1536
by: Gelcys | last post by:
I feel as though I’m banging my head against a wall trying to get something done – Access is good at some parts and Excel at others. What I’m starting with is a txt file that I need to import weekly or monthly into either and repeat the same process, to continue to add to a monthly report so I can analyze usage of licenses from a log file. The log file looks like this: Date time user feature_used checkedin_or_checkedout 01/01/10 8:00 am...
0
7239
by: steveradaza | last post by:
Sir,Good Day..I am a newbie here and i am just learning the usage of microsoft access..can you help me solve my problem in making a running balance in a query of microsoft access 2013 of my In and Out Investment?here is the attachment of my image for the sample table and the query that i created..please help me...i am doing this table and query for almost 2 months...i beg you all please..thank you in advance...
0
8238
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
8174
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
8680
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...
0
8624
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8478
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
4082
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...
0
4176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1786
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1485
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.