Recently Eric Niebler had a tweet about volatile and thread safety and somebody replied with the link to following code from Intel TBB. void Block::shareOrphaned(intptr_t binTag, unsigned index) { MALLOC_ASSERT( binTag, ASSERT_TEXT ); // unreferenced formal parameter warning tbb::detail::suppress_unused_warning(index); STAT_increment(getThreadId(), index, freeBlockPublic); markOrphaned(); if ((intptr_t)nextPrivatizable==binTag) { // First check passed: the block is not in ..
Category : race-condition
Is there any race condition when multiple threads execute below code ? class test; test& get_my_class_instance() { static test instance; // static initialisation return instance; } Is static initialisation above guaranteed to be thread safe? Source: Windows Que..
I am given a vector and a number of threads as input and I want to return a vector with all the prime numbers in it. I do not want to split up the array and assign a fixed number of portions to each thread but I want to have the threads "grab" an element ..
I am working fixing on some coverity issues and i am confused about how to solve toctou for stat a directory and make a directory. //////////////////////////////////// // Make sure storage dir exists. If // not, create it. if( stat( dir, &statBuff ) != -1 ) { if( S_ISDIR( statBuff.st_mode ) ) { if( (dirPtr = ..
The following excerpt is taken from the website https://lwn.net/Articles/262464/ and it is dealing with read-inconsistencies of shared data structures (for which there was the RCU created): p = gp; if (p != NULL) { do_something_with(p->a, p->b, p->c); } Although this code fragment might well seem immune to misordering, unfortunately, the DEC Alpha CPU [PDF] and ..
I am trying to find the data race in my code but I just can’t seem to grasp why it happens. The data in the threads is used read-only and the only variable that is written to is protected by a critical region. I tried using the Intel Inspector but I am compiling with g++ ..
Let’s say the interface function which performs the entire operation looks like this: result_t c_worker::minimize_somethings(input_t const& obj1, input_t const& obj2) const { … } I’m working with a functor, say, compute_cost which is the core evaluator of a cost-function of an optimization algorithm. This requires obj1 und obj2 in order to perform its activity. However, ..
I have a rather strange example, and so I will just put the context out here briefly, and we can hopefully just pretend it’s a good idea. I’m using a profiler that requires regular calls to its FRAME() macro so that it knows where CPU frames of a game start and end (the object the ..
I’m running into an issue that I’m not sure is solvable in the way I want to solve it. I have a problem with a race condition. I have one project running as a C++ dll (the main engine). Then I have a second C# process that uses C++/CLI to communicate with the main engine ..
In unix I can safely modify a variable within a thread using a mutex lock like-so: int x = 0; // Global Variable we want to modify between threads. void a_thread() { pthread_mutex_lock(&lock); pthread_cond_wait(&consum,lock); //critical area x += 30; pthread_mutex_unlock(&lock); } What is the windows equivalent of this code? Source: Windows..
Recent Comments