diff --git a/cp/main.cpp b/cp/main.cpp index a651ac0..a3b928a 100644 --- a/cp/main.cpp +++ b/cp/main.cpp @@ -1,4 +1,7 @@ #include +#include +#include + void WriteStr(const char * str) { @@ -34,6 +37,7 @@ int main(int argc, char * args[]) // Open the source // A little RAII + { FileWrapper src(args[1], GENERIC_READ, OPEN_EXISTING); if (GetLastError() == ERROR_FILE_NOT_FOUND) { @@ -58,6 +62,13 @@ int main(int argc, char * args[]) break; WriteFile(dst.getHandle(), buffer, numberofbytesread, &numberofbyteswritten, NULL); } + } + std::vector 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; } \ No newline at end of file diff --git a/cp/test.txt b/cp/test.txt deleted file mode 100644 index 496a451..0000000 --- a/cp/test.txt +++ /dev/null @@ -1 +0,0 @@ -THIS IS ONLY A TEST \ No newline at end of file diff --git a/ptypes-mlock/build.bat b/ptypes-mlock/build.bat new file mode 100644 index 0000000..fd2319b --- /dev/null +++ b/ptypes-mlock/build.bat @@ -0,0 +1,4 @@ +@echo off +call ../vcppbuild.bat mlock "/link user32.lib ../ext/libs/ptypes.lib" +mlock.exe +pause \ No newline at end of file diff --git a/ptypes-mlock/build.sh b/ptypes-mlock/build.sh new file mode 100644 index 0000000..223b338 --- /dev/null +++ b/ptypes-mlock/build.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +gcc -o monitor -lptypes mlock.cpp +./main \ No newline at end of file diff --git a/ptypes-mlock/mlock.cpp b/ptypes-mlock/mlock.cpp new file mode 100644 index 0000000..4ff1f38 --- /dev/null +++ b/ptypes-mlock/mlock.cpp @@ -0,0 +1,38 @@ +#include +#include +#include +#include + +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); +} \ No newline at end of file