Threads

Discussion in 'C Programming' started by Poly-poly man, Jul 27, 2006.

  1. 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
    Poly-poly man, Jul 27, 2006
    #1
    1. Advertising

  2. 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().
    Ancient_Hacker, Jul 27, 2006
    #2
    1. Advertising

  3. Poly-poly man

    Guest

    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, 2006
    #3
  4. Poly-poly man

    Skarmander Guest

    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.
    Skarmander, Jul 27, 2006
    #4
  5. 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.
    Christopher Benson-Manica, Jul 27, 2006
    #5
  6. 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
    Poly-poly man, Jul 27, 2006
    #6
  7. On 27 Jul 2006 10:22:46 -0700, in comp.lang.c , "Ancient_Hacker"
    <> wrote:

    >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
    Mark McIntyre, Jul 27, 2006
    #7
  8. On Thu, 27 Jul 2006 19:36:00 GMT, in comp.lang.c , Poly-poly man
    <> wrote:

    >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
    Mark McIntyre, Jul 27, 2006
    #8
  9. On 27 Jul 2006 10:22:46 -0700, in comp.lang.c , "Ancient_Hacker"
    <> wrote:

    >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
    Mark McIntyre, Jul 27, 2006
    #9
  10. Mark McIntyre <> writes:
    > On 27 Jul 2006 10:22:46 -0700, in comp.lang.c , "Ancient_Hacker"
    > <> wrote:
    >>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) <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.
    Keith Thompson, Jul 27, 2006
    #10
  11. Mark McIntyre <> wrote:

    > On 27 Jul 2006 10:22:46 -0700, in comp.lang.c , "Ancient_Hacker"
    > <> wrote:


    > >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.
    Christopher Benson-Manica, Jul 28, 2006
    #11
  12. In article <>, Keith Thompson <> writes:
    > Mark McIntyre <> writes:
    > > On 27 Jul 2006 10:22:46 -0700, in comp.lang.c , "Ancient_Hacker"
    > > <> wrote:
    > >>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

    Web 2.0 is ... like talking to people - without the pesky annoyance of
    other people. -- Martin Wood
    Michael Wojcik, Jul 28, 2006
    #12
  13. In article <>,
    Michael Wojcik <> wrote:
    >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
    Walter Roberson, Jul 28, 2006
    #13
  14. On Thu, 27 Jul 2006 17:17:57 UTC, Poly-poly man
    <> wrote:

    > 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!
    Herbert Rosenau, Jul 28, 2006
    #14
  15. On Thu, 27 Jul 2006 22:31:52 GMT, in comp.lang.c , Keith Thompson
    <> wrote:

    >Mark McIntyre <> writes:
    >> On 27 Jul 2006 10:22:46 -0700, in comp.lang.c , "Ancient_Hacker"
    >> <> wrote:
    >>>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
    Mark McIntyre, Jul 28, 2006
    #15
  16. Poly-poly man

    av Guest

    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
    av, Jul 29, 2006
    #16
  17. On 2006-07-29, 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
    >


    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
    Andrew Poelstra, Jul 29, 2006
    #17
  18. Poly-poly man

    Ian Collins Guest

    Andrew Poelstra wrote:
    > On 2006-07-29, 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
    >>

    >
    >
    > 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.
    Ian Collins, Jul 29, 2006
    #18
  19. Poly-poly man

    av Guest

    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
    av, Jul 29, 2006
    #19
  20. On 2006-07-29, Ian Collins <> wrote:
    > Andrew Poelstra wrote:
    >> On 2006-07-29, 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
    >>>

    >>
    >>
    >> 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
    Andrew Poelstra, Jul 29, 2006
    #20
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Codemonkey
    Replies:
    1
    Views:
    408
    Ying-Shen Yu[MSFT]
    Oct 30, 2003
  2. yoda
    Replies:
    2
    Views:
    425
    =?utf-8?Q?Bj=C3=B6rn_Lindstr=C3=B6m?=
    Aug 1, 2005
  3. threads without threads

    , Aug 27, 2004, in forum: C Programming
    Replies:
    4
    Views:
    389
    William Ahern
    Aug 27, 2004
  4. Pedro Pinto

    Java Threads - Get running threads

    Pedro Pinto, Apr 8, 2008, in forum: Java
    Replies:
    2
    Views:
    1,416
    Arne Vajhøj
    Apr 9, 2008
  5. Une bévue
    Replies:
    0
    Views:
    137
    Une bévue
    Jun 14, 2006
Loading...

Share This Page