#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2010
    Posts
    9
    Rep Power
    0

    Threads in c language!!


    can any one help me out in creating thread in c language??
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,172
    Rep Power
    2222
    Threads are not supported by the C standard. Support for threads is platform-dependent; some operating systems support them and some don't. Many compilers provide libraries for accessing operating system support for threads, but some don't.

    In order to even begin to answer your question, we must know what operating system you are using. And what compiler. For example, Turbo C 2 offers absolutely no threading support, since it's a 16-bit DOS compiler; MS-DOS did not support threading.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2010
    Posts
    9
    Rep Power
    0
    i am using gcc and the opreating system is Redhat!
  6. #4
  7. <?PHP user_title("gimp"); ?>
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2005
    Location
    Internet
    Posts
    7,652
    Rep Power
    6084
    If you're looking for third-party libraries, I recommend boost threads.
    Chat Server Project & Tutorial | WiFi-remote-control sailboat (building) | Joke Thread
    “Rational thinkers deplore the excesses of democracy; it abuses the individual and elevates the mob. The death of Socrates was its finest fruit.”
    Use XXX in a comment to flag something that is bogus but works. Use FIXME to flag something that is bogus and broken. Use TODO to leave yourself reminders. Calling a program finished before all these points are checked off is lazy.
    -Partial Credit: Sun

    If I ask you to redescribe your problem, it's because when you describe issues in detail, you often get a *click* and you suddenly know the solutions.
    Ches Koblents
  8. #5
  9. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,172
    Rep Power
    2222
    pthreads, then. It's been a long time since I've played with it, but Google should yield plenty of hits.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2010
    Posts
    9
    Rep Power
    0
    any one has sample code here for implementing thread in c??

    Comments on this post

    • salem disagrees : Lazy - there are no end of tutorials on the web containing your average "hello world" as a thread programs to read - so go read some!
  12. #7
  13. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,172
    Rep Power
    2222
    Originally Posted by bonjovi4u
    any one has sample code here for implementing thread in c??
    The problem with using Google to find something is that you need to know what it's called. You need to know that both for setting the search words and for recognizing which hits would be useful.

    I gave you that. Now you can Google for information on pthreads and for sample code. Now go Google.
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2010
    Posts
    9
    Rep Power
    0
    Originally Posted by dwise1_aol
    The problem with using Google to find something is that you need to know what it's called. You need to know that both for setting the search words and for recognizing which hits would be useful.

    I gave you that. Now you can Google for information on pthreads and for sample code. Now go Google.
    i have gone through google enough found sevral pthread examples but every time i am compiling the code i get the following error...

    /tmp/ccSzMvuS.o: In function `main':
    thread.c:(.text+0x80): undefined reference to `pthread_create'
    collect2: ld returned 1 exit status

    or this



    /tmp/ccmrzvzA.o: In function `main':
    thread.c:(.text+0x3d): undefined reference to `pthread_create'
    thread.c:(.text+0x62): undefined reference to `pthread_create'
    thread.c:(.text+0x78): undefined reference to `pthread_join'
    thread.c:(.text+0x8b): undefined reference to `pthread_join'
    collect2: ld returned 1 exit status
  16. #9
  17. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,638
    Rep Power
    4247
    That means it can't find your thread library. Stick a -lthread at the end of your gcc command line.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2010
    Posts
    9
    Rep Power
    0
    Originally Posted by Scorpions4ever
    That means it can't find your thread library. Stick a -lthread at the end of your gcc command line.
    ok no the problem is solve a bit!!!

    but the code wat m trying to write is not satisfiying me following is the code!!




    #include <pthread.h>
    #include <stdio.h>

    void *PrintHello(void *threadid)
    {
    printf("Hello World!\n");
    }

    void start()
    {
    pthread_t threads[1];
    int rc;
    long t;
    rc = pthread_create(&threads[1], NULL, PrintHello, (void *)1);

    if (rc){
    printf("ERROR; return code from pthread_create() is %d\n", rc);
    exit(-1);
    }

    pthread_exit(NULL);
    }
    int main (int argc, char *argv[])
    {
    start();
    printf("Thread Still Running");
    }
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2010
    Posts
    9
    Rep Power
    0
    can any one help me with this code!!!!



    #include <pthread.h>
    #include <stdio.h>

    void *PrintHello(void *threadid)
    {
    while(1)
    {
    }
    }

    void start()
    {
    pthread_t mythread;
    rc = pthread_create(&mythread, NULL, PrintHello, NULL);

    }

    int main (int argc, char *argv[])
    {
    start();
    printf("Thread Still Running\n");
    }
  22. #12
  23. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,638
    Rep Power
    4247
    1. Please read the sticky threads and post within [code] and [/code] tags. You're not a newbie here anymore.

    2. What exactly is the problem you're having? All I see is some code pasted and no clue as to what problem you're having.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  24. #13
  25. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    1
    Rep Power
    0

    Talking How to implement coding in c program to open a URL


    New Friends at Dev Shed Forums:

    I am very new to c language.

    Going through my first class in the topic.

    I have built a program that counts down from 10 to 0 at 1 second intervals and at the end I want to open a URL that will display a rocket launch in a web browser.

    I am using a Pelles IDE compiler. Have not been able to find simple commands from the internet that this compiler or this program would accept to open URL. Any idea on how can get to work to open a URL? :

    Here is my code so far (I just need to implement the portion of coding that would open a URL):

    #include <stdio.h>
    #include <time.h>
    #include <stdlib.h>

    int main(void)

    {

    int x;


    for (x = 10; x >= 0; --x)


    {

    printf("%d\n", x);
    if(x <= 10);


    {
    _sleep(1);
    }




    }


    return(0);

    }
  26. #14
  27. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,892
    Rep Power
    481
    please start a new thread for a new topic.
    please read the information at my signature to post your code.

    Look up the system command.

    Meanwhile, if you're on Windows NT or perhaps other Microsoft systems, a c code like
    system("start ie rocket.html");
    might work.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo