How can I create multithreading in C for Windows?

I don’t know how I can create threads in C, I saw a review about the pthread.h library, but then I heard that it is only for Linux OS, I have a function in which there is a timer, I want to create a thread with this function , but I don’t know either the library that I need to use, or the syntax for writing code, if someone could provide me with simple code with threads or say what things I need to put and the function parameter.

Here its function I creates a countdown of the time during which the user applies: I need to create a stream with this function.

Function (countdown):

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

void countdown(int second)
{
    int secs = 1;
    time_t unix;
    struct tm * timeinfo;
    time(&unix);
    timeinfo = localtime(&unix);
    int t1 = timeinfo->tm_sec;
    int t2 = timeinfo->tm_sec;
    int i = 0;

    while(1 == 1)
    {
       time(&unix);
       timeinfo = localtime(&unix);
       if((t1 + i)  == timeinfo->tm_sec)
       {
              system("cls");
              printf("Time left %d\n", timeinfo->tm_sec - t2 - second);
              i++;
       }
       if(timeinfo->tm_sec >= (t1 + second))
       {
           system("cls");
           puts("Your time its done");
           break;
       }

    }
}

int main()
{
    int limit;
    printf("How much time would you like (In secs): ");
    scanf("%d", &limit);
    countdown(limit);

    system("PAUSE");
    return 0;
}
+6
source share
4

winapi
http://www.cs.rpi.edu/academics/courses/netprog/WindowsThreads.html

C , , java ( ). , . Unix- c c ANSI/ISO, posix, pthreads - posix-threads. Windows C - MS, -. , , glib qt (Windows, Linux, other * nix). , posix . Cigwin posix, . MinGW posix- win32.

, glib qt, , , .

glib GTK , QT , ++.

+4

, Windows. API Win32 CreateThread, . , C ( ), _beginthread, process.h.

_beginthread , , C .

+3

pthreads / - , MinGW pthreads-win32. , , . Windows, , , , WinAPI, redcomet.

+3

There is no stream concept in the C standard library. A thread is usually a concept in the OS. You can use win32api to process threads the same way you use pthread on linux (actually it is not).

To learn more about win32api, go to MSDN.

How to create a thread with win32api:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms682516(v=vs.85).aspx

+2
source

All Articles