Thread: creating thread/sleep

  1. #1
    Registered User
    Join Date
    Jun 2010
    Posts
    3

    creating thread/sleep

    I need to create a thread, and have do some processing then sleep for certain time, then wake up do more processing,etc.

    I'm used to Java programming and this would be super easy. Is there an easy way to implent this in anis C. thanks!!

  2. #2
    Registered User
    Join Date
    Sep 2007
    Posts
    1,012
    No. C has no concept of threading. You'll have to look at OS-specific functions for that.

    On UNIX-like systems you can use POSIX threads, which means you're portable to a number of different operating systems.

  3. #3
    Grey Wizard C_Sparky's Avatar
    Join Date
    Sep 2009
    Posts
    50
    Using the Win32 API:

    -Create a function with a return type of VOID or DWORD WINAPI
    -The function's parameter must be the type of LPVOID or void*
    -Make a call to CreateThread() while passing the function into the 3rd parameter

    Ex:
    Code:
    CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&my_thread, NULL, 0, 0);

  4. #4
    VIM addict
    Join Date
    May 2009
    Location
    Chennai, India
    Posts
    43
    In case of linux you can use either POSIX (pthread) or GDK (g_threads). Here is the link to get started

    1. POSIX
    2. GDK

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling GNU MP
    By mattnp12 in forum C Programming
    Replies: 3
    Last Post: 06-23-2011, 03:58 PM
  2. creating C programs to test memory usage
    By dsollen in forum C++ Programming
    Replies: 1
    Last Post: 04-20-2010, 10:12 AM
  3. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  4. Creating a rain effect...
    By Raigne in forum Game Programming
    Replies: 11
    Last Post: 12-04-2007, 05:30 PM
  5. Help creating lists of pointers
    By The_Kingpin in forum C Programming
    Replies: 2
    Last Post: 12-11-2004, 08:10 PM