Thread: Multi Threading

  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    4

    Multi Threading

    I am creating a program where a user enters a really long code using a pattern, and the computer can tell them the pattern they used. But it might take a long time for the pc to try a lot of combinations one at a time. Is there a way to get the computer to try many patterns at once?



    Sincerely,
    Art

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    You can use multi-threading for this, but from the description of your problem, I'm willing to bet you would have a tough time implementing it such that it goes faster with multiple threads than it does with 1 thread.

  3. #3
    Registered User
    Join Date
    Jul 2009
    Posts
    4
    I want to try it partly to see if I can do it. But how would I get it to multi thread? Is there a special header I need to include?

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Threading is not built into the C language, so you have to use an external Library. What OS are you using?

  5. #5
    Registered User
    Join Date
    Jul 2009
    Posts
    4
    Windows Vista 64 Bit, why?

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    C has, or at least Microsoft's implementation has, _beginthread and _beginthreadex to start threads.
    Unfortunately C lacks any sort of synchronization functions.
    I would go read up on Threading on MSDN, because you will need to learn about threading in general and the problems it may cause and what Windows-specific API you need to use (hence the what OS question).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    A good start would be to read everything on this page.

  8. #8
    Registered User
    Join Date
    Jul 2009
    Posts
    4
    thanks for everyone's help. i definitely have enough to keep me busy for a while

  9. #9
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by gametek101 View Post
    thanks for everyone's help. i definitely have enough to keep me busy for a while
    Wait 'til he finds out about that "lack of synchronization" issue in C!
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  10. #10
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Well if you can say that C lacks synchronization, you can just as easily say C lacks threading entirely. Either way, you need to make calls to the OS to perform these functions. I think the biggest wakeup call for people who start multi-threaded programming is when they realize they have to think about synchronization in the first place

  11. #11
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by bithub View Post
    Either way, you need to make calls to the OS to perform these functions.
    Could there be a language where this is not true?
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  12. #12
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Quote Originally Posted by MK27 View Post
    Could there be a language where this is not true?
    Yeah, Java for instance has threading as part of the standard language.

  13. #13
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by bithub View Post
    Yeah, Java for instance has threading as part of the standard language.
    Hmmm, I guess in that sense so does javascript -- altho there are no "threading" functions, you can

    Quote Originally Posted by elated.com
    setTimeout() doesn't halt the execution of the script during the timeout period; it merely schedules the specified expression to be run at the specified time. After the call to setTimeout() the script continues normally, with the timer running in the background.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  14. #14
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by MK27 View Post
    Could there be a language where this is not true?
    It will be, in C++0x, as well.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  15. #15
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    Unless you're already an experienced programmer, with excellent debug skills, trying to debug a badly threaded program with a race condition is a real eye opener.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. overlapped I/O and multi threading
    By krishnampkkm in forum C++ Programming
    Replies: 2
    Last Post: 06-22-2009, 03:27 PM
  2. Multi Threading
    By beon in forum C Programming
    Replies: 5
    Last Post: 12-04-2006, 09:21 PM
  3. Replies: 6
    Last Post: 06-02-2006, 08:32 AM
  4. starting to learn multi threading
    By hanhao in forum C++ Programming
    Replies: 2
    Last Post: 06-09-2004, 01:44 PM
  5. Multi Threading
    By IceBall in forum C Programming
    Replies: 7
    Last Post: 07-13-2003, 03:01 PM