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

How to make two simultaneously running infinite whiles in C?

2
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.Thread(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(tid, 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 1216
artnx
2
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
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...
1
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
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...
1
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...
8
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...
0
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...
6
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...
2
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...
0
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...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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.