Threads

P

Poly-poly man

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
 
A

Ancient_Hacker

Poly-poly man said:
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().
 
S

spibou

Ancient_Hacker said:
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
 
S

Skarmander

Ancient_Hacker said:
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.
 
C

Christopher Benson-Manica

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.
 
P

Poly-poly man

Ancient_Hacker said:
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
 
M

Mark McIntyre

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
 
M

Mark McIntyre

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
 
M

Mark McIntyre

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
 
K

Keith Thompson

Mark McIntyre said:
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.
 
M

Michael Wojcik

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.
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.
 
M

Mark McIntyre

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
 
A

av

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
 
A

Andrew Poelstra

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.)
 
I

Ian Collins

Andrew said:
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 :)
 
A

av

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
 
A

Andrew Poelstra

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. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top