pthreads

How is a thread waiting for mutex put back to running?

我们两清 提交于 2021-02-08 10:28:59
问题 The context is like this: a thread tries to lock a already locked mutex the thread is put to sleep/blocking after some while, the mutex is unlocked Q1) What will happen then ? will the thread be immediately put back to running? Or kernel will still wait the running thread consume its time slice and schedule the waiting thread normally? Q2) What if the mutex is not unlocked forever? How does the kernel determine to keep the thread waiting? 回答1: Will the thread be immediately put back to

Error : LNK1104 cannot open file 'pthread.lib'

北城以北 提交于 2021-02-08 03:46:56
问题 I am trying to compile a native Linux C++ application in Windows using Visual Studio 2017. The app uses WebRtc's Acoustic Echo Cancellation(AEC) APIs to negate echo on wav files. Following is the CmakeLists.txt file: cmake_minimum_required(VERSION 2.8) project(wav-aec) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) add_subdirectory(gflags) add_definitions("-DWEBRTC_NS_FLOAT -DWEBRTC_WIN -DNOMINMAX") #-DWEBRTC_UNTRUSTED_DELAY -DWEBRTC_LINUX -DWEBRTC_POSIX

'pthread_setname_np' was not declared in this scope

跟風遠走 提交于 2021-02-07 22:39:06
问题 I have created multiple threads in my application. I want to assign a name to each pthread so I used pthread_setname_np which worked on Ubuntu but is not working on SUSE Linux. I googled it and came to know '_np' means 'non portable' and this api is not available on all OS flavors of Linux. So now I want to do it only if the API is available. How to determine whether the api is available or not ? I need something like this. #ifdef SOME_MACRO pthread_setname_np(tid, "someName"); #endif 回答1:

'pthread_setname_np' was not declared in this scope

北城以北 提交于 2021-02-07 22:38:04
问题 I have created multiple threads in my application. I want to assign a name to each pthread so I used pthread_setname_np which worked on Ubuntu but is not working on SUSE Linux. I googled it and came to know '_np' means 'non portable' and this api is not available on all OS flavors of Linux. So now I want to do it only if the API is available. How to determine whether the api is available or not ? I need something like this. #ifdef SOME_MACRO pthread_setname_np(tid, "someName"); #endif 回答1:

'pthread_setname_np' was not declared in this scope

a 夏天 提交于 2021-02-07 22:37:48
问题 I have created multiple threads in my application. I want to assign a name to each pthread so I used pthread_setname_np which worked on Ubuntu but is not working on SUSE Linux. I googled it and came to know '_np' means 'non portable' and this api is not available on all OS flavors of Linux. So now I want to do it only if the API is available. How to determine whether the api is available or not ? I need something like this. #ifdef SOME_MACRO pthread_setname_np(tid, "someName"); #endif 回答1:

How to create Semaphores in c?

拜拜、爱过 提交于 2021-02-07 18:44:58
问题 Im trying to recreate a "Blackbox" library. In my CS class when we are supposed to use Semaphores (in our on paper final) we are given a "sem.h" file. there are 3 functions one for creating a new Semaphore with an inital number of tokens, one for taking a token out of a semaphore and one for placing a token into a semaphore. at 0 tokes any thread using the blocking funktion has to wait for a token. for better understanding ive been trying to recreate this sem.h and sem.c based on some exams

Single reader multiple writers with pthreads and locks and without boost

别等时光非礼了梦想. 提交于 2021-02-07 08:58:58
问题 Consider the next piece of code. #include <iostream> #include <vector> #include <map> using namespace std; map<pthread_t,vector<int>> map_vec; vector<pair<pthread_t ,int>> how_much_and_where; pthread_cond_t CV = PTHREAD_COND_INITIALIZER; pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; void* writer(void* args) { while(*some condition*) { int howMuchPush = (rand() % 5) + 1; for (int i = 0; i < howMuchPush; ++i) { // WRITE map_vec[pthread_self()].push_back(rand() % 10); } how_much_and_where

Single reader multiple writers with pthreads and locks and without boost

早过忘川 提交于 2021-02-07 08:57:21
问题 Consider the next piece of code. #include <iostream> #include <vector> #include <map> using namespace std; map<pthread_t,vector<int>> map_vec; vector<pair<pthread_t ,int>> how_much_and_where; pthread_cond_t CV = PTHREAD_COND_INITIALIZER; pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; void* writer(void* args) { while(*some condition*) { int howMuchPush = (rand() % 5) + 1; for (int i = 0; i < howMuchPush; ++i) { // WRITE map_vec[pthread_self()].push_back(rand() % 10); } how_much_and_where

Is it possible to do static initialization of mutexes in Windows?

喜欢而已 提交于 2021-02-07 06:47:21
问题 pthread supports static initialization of pthread_mutex_t using PTHREAD_MUTEX_INITIALIZER. Is it possible to achieve a similar static mechanism for mutex initialization using Windows mutex? 回答1: No, since Windows mutex are handles, they must be initialized with CreateMutex(). Note that the static initialization of pthread_mutex_t using PTHREAD_MUTEX_INITIALIZER is not a real init, it will be done internally at the first call to pthread_mutex_lock() or pthread_mutex_trylock() 回答2: Yes, this is

Does each thread have its own stack?

余生颓废 提交于 2021-02-05 21:38:32
问题 When I create multiple threads from a process, then does each thread have its own stack, or is it that they share the stack of their parent process. What happens when a thread makes a system call? Do threads also maintain their own kernel stack like processes? 回答1: Yes threads have their own stacks and their own kernel stacks (e.g. linux). When a thread makes a system call, you trap into kernel mode (from user mode), you pass the arguments to the kernel, the arguments are checked, the kernel