#include "stdafx.h"
#include <omp.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <windows.h>
using namespace std;
#define watki 4
DWORD dword;
int zmienna = 0;
VOID FunkcjaBezparametrowa(VOID)
{
LPVOID lpvoid;
lpvoid = TlsGetValue(dword);
int licznik = reinterpret_cast<int>(lpvoid);
licznik++;
TlsSetValue(dword, reinterpret_cast<LPVOID>(licznik));
lpvoid = TlsGetValue(dword);
cout << "Funkcja bezparametrowa watek " << GetCurrentThreadId() << " : licznik = " << lpvoid << endl;
Sleep(100);
}
DWORD WINAPI ThreadFunc(VOID)
{
LPVOID lpvoid;
lpvoid = (LPVOID)LocalAlloc(LPTR, 256);
int licznik = zmienna++;
TlsSetValue(dword, reinterpret_cast<LPVOID>(licznik));
lpvoid = TlsGetValue(dword);
cout << "Watek " << GetCurrentThreadId() << " : licznik startowy = " << lpvoid << endl;
for (int i = 0; i < 30; i++) FunkcjaBezparametrowa();
lpvoid = TlsGetValue(dword);
cout << "Watek " << GetCurrentThreadId() << " : licznik koncowy =" << lpvoid << endl;
LocalFree((HLOCAL)lpvoid);
return 0;
}
int main(VOID)
{
DWORD IDThread;
HANDLE hThread[watki];
int i;
dword = TlsAlloc();
for (i = 0; i < watki; i++)
{
hThread[i] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ThreadFunc, NULL, 0, &IDThread);
}
for (i = 0; i < watki; i++)
WaitForSingleObject(hThread[i], INFINITE);
TlsFree(dword);
cin.ignore();
return 0;
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}