mutex

Throwing an exception from std::call_once

戏子无情 提交于 2019-12-07 05:04:41
问题 The C++ Standard states the following about the execution of std::call_once with functions that throw exceptions (§30.4.4.2/2): 2/ Effects: An execution of call_once that does not call its func is a passive execution. An execution of call_once that calls its func is an active execution. An active execution shall call INVOKE (DECAY_- COPY ( std::forward(func)), DECAY_COPY (std::forward(args))...). If such a call to func throws an exception the execution is exceptional, otherwise it is

Scenario: Global variables in DLL which is used by Multi-threaded Application

僤鯓⒐⒋嵵緔 提交于 2019-12-07 04:10:31
问题 Few months back, I had come across this interesting scenario asked by a guy (on orkut). Though, I've come up with a "non-portable" solution to this problem (have tested it with small code), but still would like to know what you guys have to say and suggest. Suppose, I created a DLL, exporting some functionalities, written in C++, for single threaded client . This DLL declares lots of global variables, some maybe const variables (read-only) and others are modifiable. Anyway, later things

Can a pthread_mutex_t be moved in memory?

余生长醉 提交于 2019-12-07 03:52:19
问题 I would like to build a dynamic malloced array of pthread_mutex that will grow over time (adding more mutexes). My question is whether they will still work if the array gets moved with realloc(). My concern is that pthread_mutex_init() might somehow set up internal information that depends on the address of the mutex at that moment. To be more specific, here is a toy snippet that shows the issue: pthread_mutex_t *my_mutexes = (pthread_mutex_t *) malloc (sizeof(pthread_mutex_t)); pthread_mutex

What is the use for a Mutex if you can't name it?

蹲街弑〆低调 提交于 2019-12-07 03:30:47
问题 I am having a hard time figuring out what good a mutex is without naming it. Specifically I want to make my Windows Mobile 6.5 app single-instance. There are a few questions and answers on this site about how to do that - and the best ones seem to use named mutexes. Unfortunately the CTORS for mutexes in compact framework do not take a string - one can only create a mutex. Now, what good is a mutex if it has no associated ID? Am I missing something? How do I use a mutex to protect a resource

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

て烟熏妆下的殇ゞ 提交于 2019-12-07 03:16:57
问题 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. 回答1: If you're worried about these issues, Robust Mutexes may

Delete a mutex from another process

会有一股神秘感。 提交于 2019-12-07 02:25:54
问题 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

How to alter the recursive locking behaviour of Windows Mutex?

▼魔方 西西 提交于 2019-12-07 02:21:46
问题 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? 回答1: 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

std::timed_mutex::try_lock* fail spuriously

谁说我不能喝 提交于 2019-12-06 19:39:20
问题 By try_lock* , I take to mean try_lock() , try_lock_for() , and try_lock_until() . According to cppreference, all three methods may just fail spuriously. Following is quoted from the description for try_lock_for() As with try_lock() , this function is allowed to fail spuriously and return false even if the mutex was not locked by any other thread at some point during timeout_duration . I know that spurious wakeup may happen with std::condition_variable and the rationale behind it. But, what

App hangs at __psynch_mutexwait

与世无争的帅哥 提交于 2019-12-06 19:27:19
问题 Our app seems to semi-randomly hang at psynch_mutexwait. It seems to be related to a background process that updates a bunch of data stored in CoreData - but I've been completely unable to figure out just who is locking on what to cause the deadlock. Following is the complete stack trace that lldb gives me - which is obviously incomplete, AND the last frame of Thread 1 is bogus. I had a breakpoint in that method a few lines before that, and it was never hit. Is there ANY way of figuring out

Do I really need mutex lock in this case?

孤街醉人 提交于 2019-12-06 16:43:24
Consider we have three thread, bool status_flag[500] array, and working situations as follow : Two threads only writing in status_flag array at different index . while third thread is only reading at any index. All three thread writing at different index. While all three threads reading at any index. In writing operation we are just setting the flag never reset it again. status_flag [i] = true; In reading operation we are doing something like that : for(;;){ //spinning to get flag true if(status_flag [i] == true){ //do_something ; break; } } What happen if compiler optimize (branch prediction)