os-70-350

os-70-350 Commit Details


Date:2014-02-04 23:07:50 (11 years 7 months ago)
Author:Natalie Adams
Branch:master
Commit:3ec953c88fcef4e96c7705cefa094f0c76c8a8f7
Parents: ce324dbe48b25b7e9ae194d41b6ced2729f72d24
Message:Adding mlock example

Changes:

File differences

cp/main.cpp
11
2
3
4
25
36
47
......
3437
3538
3639
40
3741
3842
3943
......
5862
5963
6064
65
6166
67
68
69
70
71
72
6273
6374
#include <Windows.h>
#include <string>
#include <vector>
void WriteStr(const char * str)
{
// Open the source
// A little RAII
{
FileWrapper src(args[1], GENERIC_READ, OPEN_EXISTING);
if (GetLastError() == ERROR_FILE_NOT_FOUND)
{
break;
WriteFile(dst.getHandle(), buffer, numberofbytesread, &numberofbyteswritten, NULL);
}
}
std::vector<wchar_t> wstr;
std::string x = args[1];
wstr.resize(x.size() + 1);
size_t convertedChars = 0;
mbstowcs_s(&convertedChars, &wstr[0], x.size() + 1, x.c_str(), _RUNCATE
DeleteFileA(args[1]);
return 0;
}
cp/test.txt
1
THIS IS ONLY A TEST
ptypes-mlock/build.bat
1
2
3
4
@echo off
call ../vcppbuild.bat mlock "/link user32.lib ../ext/libs/ptypes.lib"
mlock.exe
pause
ptypes-mlock/build.sh
1
2
3
4
#!/bin/bash
gcc -o monitor -lptypes mlock.cpp
./main
ptypes-mlock/mlock.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <ptypes/ptypes.h>
#include <ptypes/pasync.h>
#include <stdio.h>
#include <windows.h>
USING_PTYPES
#define LOOP 20000
volatile int counter = -1;
volatile unsigned long gvar = 0;
mutex m_lock;
DWORD WINAPI produce(void* data) {
scopelock l(m_lock);
int i = 0;
for (i = 0; i < LOOP; i++)
gvar++;
return 0;
}
DWORD WINAPI consume(void* data) {
scopelock l(m_lock);
int i = 0;
for (i = 0; i < LOOP; i++)
gvar--;
return 0;
}
int main() {
HANDLE thread1, thread2;
thread1 = CreateThread(NULL, 0, produce, NULL, 0, NULL);
thread2 = CreateThread(NULL, 0, consume, NULL, 0, NULL);
WaitForSingleObject(thread1, INFINITE);
WaitForSingleObject(thread2, INFINITE);
printf("gvar = %lu\n", gvar);
}

Archive Download the corresponding diff file

Branches

Number of commits:
Page rendered in 0.12379s using 14 queries.