473,395 Members | 1,742 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

I'm a total newbie to threads, but am generally good with c. I'm trying to
run a program that might take a while, but system by itself does not return
until the program is finished. I thought that threads would work, because I
could send system to run on a thread then continue with the program. I
attempted, but it seems too act exactly like just running "system" byu
itself, but it gives me a Segmentation Fault and exits. Can someone PLEASE
show me how to do this correctly?

Oh, and if it matters, I'm trying to do it within a gtk callback.

tia,
poly-p man
Jul 27 '06 #1
24 2361

Poly-poly man wrote:
I'm a total newbie to threads, but am generally good with c. I'm trying to
run a program that might take a while, but system by itself does not return
until the program is finished. I thought that threads would work, because I
could send system to run on a thread then continue with the program. I
attempted, but it seems too act exactly like just running "system" byu
itself, but it gives me a Segmentation Fault and exits. Can someone PLEASE
show me how to do this correctly?

Oh, and if it matters, I'm trying to do it within a gtk callback.

tia,
poly-p man
Heavens, man, don't you know the C mantra: K & R worked with a 1-CPU
machine, and so it will be for all us descendants, for now and forever,
amen.

Never mind that the cheapest computer at Wal-MArt will soon be a
dual-core AMD.

But to answer your question, you can't do that with threads, you 'll
have to spin off a separate process, with fork or somesuch. Or on
Unix/Linux put an ampersand on the end of the command you pass to
system().

Jul 27 '06 #2
Ancient_Hacker wrote:
Poly-poly man wrote:
I'm a total newbie to threads, but am generally good with c. I'm trying to
run a program that might take a while, but system by itself does not return
until the program is finished. I thought that threads would work, because I
could send system to run on a thread then continue with the program. I
attempted, but it seems too act exactly like just running "system" byu
itself, but it gives me a Segmentation Fault and exits. Can someone PLEASE
show me how to do this correctly?

Oh, and if it matters, I'm trying to do it within a gtk callback.

tia,
poly-p man

Heavens, man, don't you know the C mantra: K & R worked with a 1-CPU
machine, and so it will be for all us descendants, for now and forever,
amen.
I've never heard of such a mantra nor do I see how it is applicable
since
the original poster did not say that he works on a machine with more
than
one CPUs.

Anyway the opening post is definitely out of topic here. Poly man I
think
that a newsgroup dedicated to your operating system will be the most
likely
to be of assistance.

Spiros Bousbouras

Jul 27 '06 #3
Ancient_Hacker wrote:
Poly-poly man wrote:
>I'm a total newbie to threads, but am generally good with c. I'm trying to
run a program that might take a while, but system by itself does not return
until the program is finished. I thought that threads would work, because I
could send system to run on a thread then continue with the program. I
attempted, but it seems too act exactly like just running "system" byu
itself, but it gives me a Segmentation Fault and exits. Can someone PLEASE
show me how to do this correctly?

Oh, and if it matters, I'm trying to do it within a gtk callback.

Heavens, man, don't you know the C mantra: K & R worked with a 1-CPU
machine, and so it will be for all us descendants, for now and forever,
amen.
That's not even close to the C mantra.
Never mind that the cheapest computer at Wal-MArt will soon be a
dual-core AMD.
C: the language of choice for dual-core AMDs.
But to answer your question, you can't do that with threads, you 'll
have to spin off a separate process, with fork or somesuch. Or on
Unix/Linux put an ampersand on the end of the command you pass to
system().
That's more like it.

S.
Jul 27 '06 #4
sp****@gmail.com wrote:
Anyway the opening post is definitely out of topic here. Poly man I
think
that a newsgroup dedicated to your operating system will be the most
likely
to be of assistance.
Or perhaps comp.programming.threads.

--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
Jul 27 '06 #5
Ancient_Hacker wrote:
>
Poly-poly man wrote:
>I'm a total newbie to threads, but am generally good with c. I'm trying
to run a program that might take a while, but system by itself does not
return until the program is finished. I thought that threads would work,
because I could send system to run on a thread then continue with the
program. I attempted, but it seems too act exactly like just running
"system" byu itself, but it gives me a Segmentation Fault and exits. Can
someone PLEASE show me how to do this correctly?

Oh, and if it matters, I'm trying to do it within a gtk callback.

tia,
poly-p man

Heavens, man, don't you know the C mantra: K & R worked with a 1-CPU
machine, and so it will be for all us descendants, for now and forever,
amen.

Never mind that the cheapest computer at Wal-MArt will soon be a
dual-core AMD.

But to answer your question, you can't do that with threads, you 'll
have to spin off a separate process, with fork or somesuch. Or on
Unix/Linux put an ampersand on the end of the command you pass to
system().
Thanks, I never realized that it was something so simple like that.

I was under the impression that threads worked without multi-cpu computers,
because Linus Torvalds's terminal emulator program (read "Just for Fun")
worked by threads, and that was on some ancient 386 of earlier.

oh well, I'll learn about them later.
poly-p man
Jul 27 '06 #6
On 27 Jul 2006 10:22:46 -0700, in comp.lang.c , "Ancient_Hacker"
<gr**@comcast.netwrote:
>Heavens, man, don't you know the C mantra: K & R worked with a 1-CPU
machine, and so it will be for all us descendants, for now and forever,
amen.
Dork.

--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Jul 27 '06 #7
On Thu, 27 Jul 2006 19:36:00 GMT, in comp.lang.c , Poly-poly man
<py***********@gmail.comwrote:
>I was under the impression that threads worked without multi-cpu computers,
They do, and Ancient Hacker is talking rubbish. As usual.

He has told you how to run multiple processes, not multiple threads.
>because Linus Torvalds's terminal emulator program (read "Just for Fun")
worked by threads, and that was on some ancient 386 of earlier.
Correct.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Jul 27 '06 #8
On 27 Jul 2006 10:22:46 -0700, in comp.lang.c , "Ancient_Hacker"
<gr**@comcast.netwrote:
>But to answer your question, you can't do that with threads, you 'll
have to spin off a separate process, with fork or somesuch. Or on
Unix/Linux put an ampersand on the end of the command you pass to
system().
This is completely wrong. This is how to create new /processes/ not
/threads/

Please stop answering offtopic questions here, especially since you
don't seem to actually know the answers
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Jul 27 '06 #9
Mark McIntyre <ma**********@spamcop.netwrites:
On 27 Jul 2006 10:22:46 -0700, in comp.lang.c , "Ancient_Hacker"
<gr**@comcast.netwrote:
>>But to answer your question, you can't do that with threads, you 'll
have to spin off a separate process, with fork or somesuch. Or on
Unix/Linux put an ampersand on the end of the command you pass to
system().

This is completely wrong. This is how to create new /processes/ not
/threads/
Which is exactly what he said. Re-read the above paragraph: "... you
can't do that with threads, you 'll have to spin off a separate
process, with fork or somesuch."
Please stop answering offtopic questions here, especially since you
don't seem to actually know the answers
Yes, both threads and processes are off-topic here. They're topical
in comp.programming.threads and comp.unix.programmer, respectively.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jul 27 '06 #10
Mark McIntyre <ma**********@spamcop.netwrote:
On 27 Jul 2006 10:22:46 -0700, in comp.lang.c , "Ancient_Hacker"
<gr**@comcast.netwrote:
Heavens, man, don't you know the C mantra: K & R worked with a 1-CPU
machine, and so it will be for all us descendants, for now and forever,
amen.
Dork.
I would have said "troll" or "idiot", personally, but YMMV.

--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
Jul 28 '06 #11

In article <ln************@nuthaus.mib.org>, Keith Thompson <ks***@mib.orgwrites:
Mark McIntyre <ma**********@spamcop.netwrites:
On 27 Jul 2006 10:22:46 -0700, in comp.lang.c , "Ancient_Hacker"
<gr**@comcast.netwrote:
>But to answer your question, you can't do that with threads, you 'll
have to spin off a separate process, with fork or somesuch. Or on
Unix/Linux put an ampersand on the end of the command you pass to
system().
This is completely wrong. This is how to create new /processes/ not
/threads/

Which is exactly what he said. Re-read the above paragraph: "... you
can't do that with threads, you 'll have to spin off a separate
process, with fork or somesuch."
Nonetheless, the answer is still very likely wrong. It's possible
that the OP can't successfully call system() in a thread other
than the process main thread in his implementation, but how AH
came to that conclusion is unclear and suspect, since we know
nothing about the OP's implementation other than that it provides
the system function (and so is probably hosted), provides threads of
some sort, and has some abnormal exit condition that the OP refers
to as "a Segmentation Fault". (That might be a POSIX SIGSEGV, but
it might well be something else; and POSIX alone doesn't tell us
very much. OS/400 V4R3 was POSIX-compliant and UNIX-branded, IIRC.)

Oh, and that there's something called "a gtk callback" in the OP's
environment; that might be a callback function for the GNU GTK+
toolkit, say, but it might be something else entirely.

[OT] As it happens, I have just used one C implementation, plus
facilities available in the environment for that implementation,[1]
to successfully invoke the system library function in a thread other
than the program's main thread. I did not do this as any sort of
"gtk callback", but unless AH's claim was founded specifically on
this requirement, it would appear that he is, indeed, talking
rubbish.

[Further OT] The answer is suspect anyway, since AH mentions Unix,
and in Unix system is required to create a new process "as if by
fork". See SUSv3 / IEEE 1003.1-2004. Thus his answer, as written,
is nonsensical; the OP is already creating a process, if he is
using a Unix implementation.

To the OP: threads, segmentation faults, and gtk are not part of
the standard C language. You might get more helpful answers - such
as more specific redirects - if you include information about your
environment when you ask questions.
Please stop answering offtopic questions here, especially since you
don't seem to actually know the answers

Yes, both threads and processes are off-topic here. They're topical
in comp.programming.threads and comp.unix.programmer, respectively.
*Unix* processes are topical in comp.unix.programmer. We don't know
that the OP's processes are.
[1] gcc -ansi -pedantic -Wall, version 2.96, on Red Hat Linux 7.1
(Linux 2.4.7-10 #1 i686), plus pthreads from glibc-devel-2.2.4-13;
because I happened to have it handy.

--
Michael Wojcik mi************@microfocus.com

Web 2.0 is ... like talking to people - without the pesky annoyance of
other people. -- Martin Wood
Jul 28 '06 #12
In article <ea********@news1.newsguy.com>,
Michael Wojcik <mw*****@newsguy.comwrote:
>OS/400 V4R3 was POSIX-compliant and UNIX-branded, IIRC.)
Unless IBM's OS/400 happens to be aka AIX 5L, it is not among the OSes
certified by the OpenGroup.

http://www.opengroup.org/openbrand/register/ibm.htm
--
I was very young in those days, but I was also rather dim.
-- Christopher Priest
Jul 28 '06 #13
On Thu, 27 Jul 2006 17:17:57 UTC, Poly-poly man
<py***********@gmail.comwrote:
I'm a total newbie to threads, but am generally good with c.
C knows nothing about threads. Go and ask in a group that is for
programming (C) on your OS.
--
Tschau/Bye
Herbert

Visit http://www.ecomstation.de the home of german eComStation
eComStation 1.2 Deutsch ist da!
Jul 28 '06 #14
On Thu, 27 Jul 2006 22:31:52 GMT, in comp.lang.c , Keith Thompson
<ks***@mib.orgwrote:
>Mark McIntyre <ma**********@spamcop.netwrites:
>On 27 Jul 2006 10:22:46 -0700, in comp.lang.c , "Ancient_Hacker"
<gr**@comcast.netwrote:
>>>But to answer your question, you can't do that with threads, you 'll
have to spin off a separate process, with fork or somesuch. Or on
Unix/Linux put an ampersand on the end of the command you pass to
system().

This is completely wrong. This is how to create new /processes/ not
/threads/

Which is exactly what he said.
yeah, but
a) the question was about threads and
b) the OP's response made me worry that he mistook the comment from
Ancient Hacker for a solution.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Jul 28 '06 #15
av
On 27 Jul 2006 10:22:46 -0700, Ancient_Hacker wrote:
>Poly-poly man wrote:
>I'm a total newbie to threads, but am generally good with c. I'm trying to
>Heavens, man, don't you know the C mantra: K & R worked with a 1-CPU
machine, and so it will be for all us descendants, for now and forever,
amen.

Never mind that the cheapest computer at Wal-MArt will soon be a
dual-core AMD.

But to answer your question, you can't do that with threads, you 'll
have to spin off a separate process, with fork or somesuch. Or on
Unix/Linux put an ampersand on the end of the command you pass to
system().
why globals are not ok in multitread enviroment?

the only right thing to do is have a copy of all global writable data
(memory space too) in each tread

Jul 29 '06 #16
On 2006-07-29, av <av@ala.awrote:
why globals are not ok in multitread enviroment?

the only right thing to do is have a copy of all global writable data
(memory space too) in each tread
This is so off-topic that I'll take the opportunity to help you with your
grammar (I believe that you asked for help a few days ago, and no one yet
has posted for you):
1) Capitalize the first letter of a sentence.
2) Capitalize abbreviations and acronyms (OK, IMHO, etc)
3) Capitalize the word `I'.
4) End each sentence with a period.
5) Would you please end each question with a question mark?
6) Please spell all words correctly; there are online dictionaries to help
you out. (This isn't nearly as important as the others in most cases.)

--
Andrew Poelstra <website down>
To reach my email, use <email also down>
New server ETA: 42
Jul 29 '06 #17
Andrew Poelstra wrote:
On 2006-07-29, av <av@ala.awrote:
>>why globals are not ok in multitread enviroment?

the only right thing to do is have a copy of all global writable data
(memory space too) in each tread


This is so off-topic that I'll take the opportunity to help you with your
grammar (I believe that you asked for help a few days ago, and no one yet
has posted for you):
4) End each sentence with a period.
Or a full stop :)

--
Ian Collins.
Jul 29 '06 #18
av
On Sat, 29 Jul 2006 08:36:47 +0200, av wrote:
>why globals are not ok in multitread enviroment?

the only right thing to do is have a copy of all global writable data
(memory space too) in each tread
unless there are 1 000 000 threads (and so a 1000 cpu that work all
togeter) and this could be possible in the future
Jul 29 '06 #19
On 2006-07-29, Ian Collins <ia******@hotmail.comwrote:
Andrew Poelstra wrote:
>On 2006-07-29, av <av@ala.awrote:
>>>why globals are not ok in multitread enviroment?

the only right thing to do is have a copy of all global writable data
(memory space too) in each tread


This is so off-topic that I'll take the opportunity to help you with your
grammar (I believe that you asked for help a few days ago, and no one yet
has posted for you):
4) End each sentence with a period.

Or a full stop :)
My original post did say `full stop', but I decided that that could mean
a period, a semicolon, (perhaps) a comma, a question mark, and a few
others. I decided that just saying `period' would be easier. :-)

--
Andrew Poelstra <website down>
To reach my email, use <email also down>
New server ETA: 42
Jul 29 '06 #20

Poly-poly man wrote:
I'm a total newbie to threads, but am generally good with c. I'm trying to
run a program that might take a while, but system by itself does not return
until the program is finished. I thought that threads would work, because I
could send system to run on a thread then continue with the program. I
attempted, but it seems too act exactly like just running "system" byu
itself, but it gives me a Segmentation Fault and exits. Can someone PLEASE
show me how to do this correctly?
man daemon

Tom

Jul 29 '06 #21
Andrew Poelstra posted:

My original post did say `full stop', but I decided that that could mean
a period, a semicolon, (perhaps) a comma, a question mark, and a few
others. I decided that just saying `period' would be easier. :-)

In my part of the world, (Ireland, Europe), the term "fullstop" unambiguously
refers to the little dot that you put at the end of a sentence -- it never
means semi-colon, comma, etc.

--

Frederick Gotham
Jul 29 '06 #22
Frederick Gotham said:
Andrew Poelstra posted:

>My original post did say `full stop', but I decided that that could mean
a period, a semicolon, (perhaps) a comma, a question mark, and a few
others. I decided that just saying `period' would be easier. :-)


In my part of the world, (Ireland, Europe), the term "fullstop"
unambiguously refers to the little dot that you put at the end of a
sentence -- it never means semi-colon, comma, etc.
In my part of the world (Mercia, British Isles) we put a space at the
half-way point: "full stop".

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Jul 29 '06 #23
Richard Heathfield posted:
In my part of the world (Mercia, British Isles) we put a space at the
half-way point: "full stop".

English, as a language, is notorious for its inconsistency when it comes to
the syntax of compound words; the following three terms are acceptable:

hummingbird
humming bird
humming-bird

--

Frederick Gotham
Jul 29 '06 #24

[Apologies for the late reply; due to the unusually hot weather earlier
this week I was not running my usual Usenet client machine.]
In article <ea**********@canopus.cc.umanitoba.ca>, ro******@ibd.nrc-cnrc.gc.ca (Walter Roberson) writes:
In article <ea********@news1.newsguy.com>,
Michael Wojcik <mw*****@newsguy.comwrote:
OS/400 V4R3 was POSIX-compliant and UNIX-branded, IIRC.)

Unless IBM's OS/400 happens to be aka AIX 5L, it is not among the OSes
certified by the OpenGroup.

http://www.opengroup.org/openbrand/register/ibm.htm
I thought OS/400 had received the UNIX 95 brand, back when that was
still current, but it appears that was OS/390. OS/400 PASE is
"designed to meet" UNIX 95:

http://www-03.ibm.com/servers/enable.../faq_unix.html

but apparently not actually branded.

--
Michael Wojcik mi************@microfocus.com

Don't forget your fighting spirit at each balls you pitch!
-- Tornado Boy Volunteer Staff International
Aug 4 '06 #25

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

Similar topics

3
by: Ronan Viernes | last post by:
Hi, I have created a python script (see below) to count the maximum number of threads per process (by starting new threads continuously until it breaks). ###### #testThread.py import...
0
by: Al Tobey | last post by:
I was building perl 5.8.2 on RedHat Enterprise Linux 3.0 (AS) today and noticed that it included in it's ccflags "-DTHREADS_HAVE_PIDS." I am building with -Dusethreads. With newer Linux...
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...
34
by: Kovan Akrei | last post by:
Hi, I would like to know how to reuse an object of a thread (if it is possible) in Csharp? I have the following program: using System; using System.Threading; using System.Collections; ...
3
by: bygandhi | last post by:
Hi - I am writing a service which will check a process and its threads for their state ( alive or dead ). The process has 5 .net managed threads created using thread.start and each have been...
10
by: [Yosi] | last post by:
I would like to know how threads behavior in .NET . When an application create 4 threads for example start all of them, the OS task manager will execute all 4 thread in deterministic order manes,...
6
by: RahimAsif | last post by:
Hi guys, I would like some advice on thread programming using C#. I am writing an application that communicates with a panel over ethernet, collects data and writes it to a file. The way the...
3
by: mjheitland | last post by:
Hi, I like to know how many threads are used by a Threading.Timer object. When I create a Threading.Timer object calling a short running method every 5 seconds I expected to have one additional...
10
by: Darian | last post by:
Is there a way to find all the thread names that are running in a project? For example, if I have 5 threads T1, T2, T3, T4, T5...and T2, T4, and T5 are running...I want to be able to know that...
4
by: tdahsu | last post by:
All, I'd appreciate any help. I've got a list of files in a directory, and I'd like to iterate through that list and process each one. Rather than do that serially, I was thinking I should...
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:
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
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
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
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,...

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.