13 pthread_mutexattr_t * nullPtr = NULL;
14 pthread_mutex_init(&cs, nullPtr);
16 #ifdef WINDOWS_THREADS 19 #ifdef EMBARCADERO_THREADS 20 cs =
new TCriticalSection();
27 pthread_mutex_destroy(&cs);
29 #ifdef WINDOWS_THREADS 32 #ifdef EMBARCADERO_THREADS 41 pthread_mutex_lock(&cs);
43 #ifdef WINDOWS_THREADS 46 #ifdef EMBARCADERO_THREADS 55 pthread_mutex_unlock(&cs);
57 #ifdef WINDOWS_THREADS 60 #ifdef EMBARCADERO_THREADS 71 pthread_mutexattr_t * nullPtr = NULL;
72 pthread_mutex_init(&m, nullPtr);
74 #ifdef WINDOWS_THREADS 75 m = CreateMutex(NULL,
false, NULL);
78 MessageBox(NULL,
"Error",
"Fail to create Windows Mutex",
79 MB_OK | MB_ICONERROR);
83 #ifdef EMBARCADERO_THREADS 84 m =
new TMutex(
false);
91 pthread_mutex_destroy(&m);
93 #ifdef WINDOWS_THREADS 96 #ifdef EMBARCADERO_THREADS 104 pthread_mutex_lock(&m);
106 #ifdef WINDOWS_THREADS 107 WaitForSingleObject(m, INFINITE);
109 #ifdef EMBARCADERO_THREADS 117 pthread_mutex_unlock(&m);
119 #ifdef WINDOWS_THREADS 122 #ifdef EMBARCADERO_THREADS 136 #ifdef WINDOWS_THREADS 137 s = ::CreateSemaphore(NULL, 0, 1, NULL);
140 MessageBox(NULL,
"Error",
"Fail to create Windows Mutex",
141 MB_OK | MB_ICONERROR);
147 #ifdef EMBARCADERO_THREADS 149 System::UnicodeString name =
"";
150 s =
new TSemaphore(NULL, 0, max, name,
false);
163 #ifdef WINDOWS_THREADS 166 #ifdef EMBARCADERO_THREADS 178 #ifdef WINDOWS_THREADS 180 ::ReleaseSemaphore(s, 1, &pCount);
182 #ifdef EMBARCADERO_THREADS 194 #ifdef WINDOWS_THREADS 195 WaitForSingleObject(s, INFINITE);
197 #ifdef EMBARCADERO_THREADS 208 pthread_attr_t * attr = NULL;
209 int res = pthread_create(&thread, attr,
function, data);
213 #ifdef WINDOWS_THREADS 214 thread =
::CreateThread(NULL, 0, (uint64_t (__stdcall* )(
void *))
function, data, 0, NULL);
216 #ifdef EMBARCADERO_THREADS 217 thread =
new TSWXEmbarcaderoThread(
function, data);
224 pthread_join(thread, NULL);
226 #ifdef WINDOWS_THREADS 227 WaitForSingleObject(thread, INFINITE);
229 #ifdef EMBARCADERO_THREADS void DeleteSemaphore(pz_semaphore_t &s)
Implements semaphore to threads. Utility.
int InitializeSemaphore(pz_semaphore_t &s)
Semaforos.
void MutexUnlock(pz_mutex_t &m)
void LeaveCriticalSection(pz_critical_section_t &cs)
void EnterCriticalSection(pz_critical_section_t &cs)
void CreateThread(pz_thread_t &thread, void *(*function)(void *param), void *data)
Threads.
void InitializeCriticalSection(pz_critical_section_t &cs)
Critical sections.
void ThreadWaitFor(pz_thread_t &thread)
#define DebugStop()
Returns a message to user put a breakpoint in.
void MutexLock(pz_mutex_t &m)
void SemaphoreWait(pz_semaphore_t &s)
void SemaphorePost(pz_semaphore_t &s)
clarg::argString m("-m", "input matrix file name (text format)", "matrix.txt")
void DeleteMutex(pz_mutex_t &m)
namespace tht means "ThreadTools"
void InitializeMutex(pz_mutex_t &m)
Mutexes.
void DeleteCriticalSection(pz_critical_section_t &cs)