Could someone give short simple example of using threads?

I'm trying to make a simple program, but I need to use threads for that. Could someone give simple example of program that's using threads?
Thanks :D
Linux or Windows?

Maikel
windows
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <windows.h>
#include <iostream>
#include <cstdlib>

DWORD WINAPI callable(void *parameter)
{
    using namespace std;
    for (int i = 0; i < 10; i++) {
        cout << "#" << i << endl;
        Sleep(i * 1000);
    }
}

int main()
{
    HANDLE hThread1, hThread2;
    hThread1 = CreateThread(0, 0, callable, 0, 0, 0);
    
    Sleep(2000);
    hThread2 = CreateThread(0, 0, callable, 0, 0, 0);
    
    Sleep(10000);
}
http://www.boost.org/doc/libs/1_42_0/doc/html/thread.html
Boost threads should be very similar to next standard C++ threads
I was feared to confront him with more libraries. But i share your oppinion: I think the best way to use theads is via boost, since they will be included into c++0x the same or similar way.

boost libraries are much more friendly than WinAPI
thanks maikel that example really helped :D
Kondiu: i recommend you to listen to Bazzy. You will counter difficulties with WinAPI Threads, if you are not familiar with WinAPI. Originally i thought this as a joke and provided you with an half-ass example without error handling and stuff.

- The Boost Library Threads are portable and more user friendly. -

But i dont want to stop you if you insist on using WinAPI (for good reasons thats possible) but read MSDN Library and answer yourself the questions: Whats up with all the zeros i wrote there?
How to Join Threads? Whats joining? How are threads managed in Memory? All this kind of boring stuff is pretty urgent to know.
ahh ok started to work with WinAPI and almost got my program working, once I will get lil more familiar with threading ill try doing some boosts
Topic archived. No new replies allowed.