mutex

PHP 5.x syncronized file access (no database)

让人想犯罪 __ 提交于 2019-12-05 07:28:24
I'm mostly familiar with Java, C and C++ in which there are ways to control that only one thread is accessing a resource at any given time. Now I'm in search for something similar but in PHP 5.x. To formulate my problem with one example: I have an ASCII-file which only stores a number, the value of a page load counter. At application deployment the file will simply hold a 0. For each access the value will be incremented by one. The goal is to keep track of page loads. The problem comes when many users are concurrently accessing the page containing the counter. When thread A has read the

How to alter the recursive locking behaviour of Windows Mutex?

荒凉一梦 提交于 2019-12-05 06:56:32
Windows Mutex seems to allow an acquired lock to be acquired again (recursively) if the thread currently owning the lock tries to acquire it. But, posix based pthread locks don't allow such a behaviour. Is there any compile time macro or any settings which can make the windows mutex behave in the same way as the pthread mutex? As long as you program in Windows, avoid reimplementing the behavior of its Mutex. It being re-entrant by the same thread is absolutely essential for its defined behavior. A sync object without thread affinity is a semaphore that counts to 1. Use CreateSemaphore(). Fwiw,

POSIX thread exit/crash/exception-crash while holding mutex

自闭症网瘾萝莉.ら 提交于 2019-12-05 06:34:49
Is there a well defined behavior for POSIX mutex ownership in case of Thread exits Thread crashes Thread crashes due to exception Suppose thread-1 owns a mutex. And thread-2 is waiting to acquire the same mutex. And thread-1 goes the 1/2/3 scenario. What is the effect on thread-2 ? PS : I believe the behavior for spin-lock is, NOT to unblock thread-2, with reasoning that the section protected by spin-lock is in bad shape anyways. If you're worried about these issues, Robust Mutexes may be the tool you're looking for: http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutexattr

Delete a mutex from another process

南笙酒味 提交于 2019-12-05 06:19:35
Using the topic Overview - Handle Enumeration , number 5, the attempt Close mutex of another process and and information from Mutex analysis, the canary in the coal mine and discovering new families of malware/ , I have came up with: Attempt 1: http://pastebin.com/QU0WBgE5 You must open Notepad first. Needless to say, this is not working for me. I need better error checking to figure out what's going on. I don't know how to get mutex pointers in the format I see them in Process Explorer . My goal is to be able to delete/kill of the mutex handles created by a process so more than one instance

Can mutex implementations be interchanged (independently of the thread implementation)

旧时模样 提交于 2019-12-05 06:18:43
Do all mutex implementations ultimately call the same basic system/hardware calls - meaning that they can be interchanged? Specifically, if I'm using __gnu_parallel algorithms (that uses openmp ) and I want to make the classes they call threadsafe may I use boost::mutex for the locking? or must I write my own mutex such as the one described here //An openmp mutex. Can this be replaced with boost::mutex? class Mutex { public: Mutex() { omp_init_lock(&_mutex); } ~Mutex() { omp_destroy_lock(&_mutex); } void lock() { omp_set_lock(&_mutex); } void unlock() { omp_unset_lock(&_mutex); } private: omp

how to set the priority to get the mutex in C/c++

别等时光非礼了梦想. 提交于 2019-12-05 06:09:15
I have 3 process (equal priority) P1 P2 P3(timer) priority to get the mutex is as follows: P1(1 priority), P2(2 priority), P3(timer)(3 priority) If suppose p3 comes and get the mutex then p2 comes and wait for mutex after that p1 comes and it also wait for mutex if p3 release mutex then p1 should get the mutex not p2 . How to perform this in C or C++. Note : all processes are running inside threads having same priority. OS - windows Xp Since the threads have equal priority, which thread gets the lock will be rather arbitrary. It appears you want to wait on a condition variable rather than

Mutex names - best practice?

瘦欲@ 提交于 2019-12-05 04:54:30
Related to this question , what is the best practice for naming a mutex? I realize this may vary with OS and even with version (esp for Windows), so please specify platform in answering. My interest is in Win XP and Vista. Sam Saffron A really safe name for a global mutex is <a description> + <a GUID> : MyApp Single Instance Mutex : {c96f7db4-d743-4718-bef0-8533a198bcca} By using a name like this there is absolutely no chance someone else will use the same mutex name as your mutex. Sniffing around with process explorer, you can see that GUIDs are used in a few places, though in general they

C Confused on how to initialize and implement a pthread mutex and condition variable

。_饼干妹妹 提交于 2019-12-05 04:51:29
问题 I'm a little bit confused on how to initialize and implement a pthread mutex and condition variable. The goal of the program is to have producers place a set number of ints in a queue and consumers take the ints out of the queue. I must also be able to define the number of producer and consumer threads that are created. In the starter code, I am give these: // Locks & Condition Variables pthread_mutex_t lock; // Lock shared resources among theads pthread_cond_t full; // Condition indicating

POSIX C Threads. Mutex example. Don't work as expected

自作多情 提交于 2019-12-05 03:33:12
I have a big problem, I can't figure out why mutexes in C don't work as I expect. This is my code: #include <stdlib.h> #include <stdio.h> #include <pthread.h> pthread_t mythread; pthread_mutex_t mymutex; void *anotherFunc(void*) { pthread_mutex_lock(&mymutex); for(int i = 0; i < 100; i++) printf("anotherFunc\n"); pthread_mutex_unlock(&mymutex); pthread_exit(NULL); } void *func(void*) { pthread_mutex_lock(&mymutex); for(int i = 0; i < 100; i++) printf("func\n"); pthread_mutex_unlock(&mymutex); pthread_exit(NULL); } int main(int argc, char *argv[]) { pthread_mutex_init(&mymutex, NULL); pthread

mutexes with objects

走远了吗. 提交于 2019-12-05 03:20:05
问题 I'm trying to understand how to use mutexes with objects in c++. I have the following (trivial) multi-threaded code I'm using as a speed test: struct Rope{ int n, steps, offset; //std::mutex mut; Rope() {} Rope(int n, int steps, int offset) : n(n), steps(steps), offset(offset) {} void compute(){ double a[n]; for (int i=0; i<n; i++) a[i] = i + offset; for (int step=0; step<steps; step++) for (int i=0; i<n; i++) a[i] = sin(a[i]); } }; void runTest(){ int numRuns = 30; int n = 10000; int steps =