From the GCC 4.8 draft changelog: G++ now implements the C++11 thread_local keyword; this differs from the GNU __thread keyword primarily in that it allows dynamic initialization and destruction semantics. Unfortunately, this support requires a run-time penalty for references to non-function-local thread_local variables even if they don’t need dynamic initialization, so users may want to continue to use __thread for
Tag: multithreading
Context switches much slower in new linux kernels
We are looking to upgrade the OS on our servers from Ubuntu 10.04 LTS to Ubuntu 12.04 LTS. Unfortunately, it seems that the latency to run a thread that has become runnable has significantly increased from the 2.6 kernel to the 3.2 kernel. In fact the latency numbers we are getting are hard to believe. Let me be more specific
Is there some kind of equivalent to .NET’s BackgroundWorker in Vala?
I’m trying to learn Vala so I’m making a small GUI application. My main language before has been C# so things are going pretty well. However, I’ve hit the wall now. I need to connect to an external network server (using GIO) which doesn’t answer my client immediately. This makes the GUI freeze up while the program is connecting and
How to detect and find out a program is in deadlock?
This is an interview question. How to detect and find out if a program is in deadlock? Are there some tools that can be used to do that on Linux/Unix systems? My idea: If a program makes no progress and its status is running, it is deadlock. But, other reasons can also cause this problem. Open source tools are valgrind
How Linux handles threads and process scheduling
I’m trying to understand how Linux handles process scheduling and thread scheduling. I read that Linux can schedule both processes and threads. Does Linux have a thread scheduler AND a process scheduler? If yes, how do they cooperate? Answer The Linux kernel scheduler is actually scheduling tasks, and these are either threads or (single-threaded) processes. So a task (a task_struct
pthread – How to start running a new thread without calling join?
I want to start a new thread from the main thread. I can’t use join since I don’t want to wait for the thread to exit and than resume execution. Basically what I need is something like pthread_start(…), can’t find it though. Edit: As all of the answers suggested create_thread should start thread the problem is that in the simple
Is it possible to set pthread CPU affinity in OS X?
In Linux there is a sched_setaffinity() function defined in sched.h, but I can’t seem to find anything like that in Mac OS X 10.6 pthreads implementation… If it is not possible to set affinity, what is the default policy in OS X? Answer Mac OS X has Thread Affinity API and you can use it with pthread ID as thread_policy_set(pthread_mach_thread_np(pthreadId),
Why does my code run slower with multiple threads than with a single thread when it is compiled for profiling (-pg)?
I’m writing a ray tracer. Recently, I added threading to the program to exploit the additional cores on my i5 Quad Core. In a weird turn of events the debug version of the application is now running slower, but the optimized build is running faster than before I added threading. I’m passing the “-g -pg” flags to gcc for the
Is errno thread-safe?
In errno.h, this variable is declared as extern int errno; so my question is, is it safe to check errno value after some calls or use perror() in multi-threaded code. Is this a thread safe variable? If not, then whats the alternative ? I am using linux with gcc on x86 architecture. Answer Yes, it is thread safe. On Linux,
thread level memory consumption of process
How do I get per thread based memory consumption of a process in Linux? I understand that we can use /proc/pid/task/tid/statm, but thats not helping my case. All the threads show same value and its same as PID’s statm. We can do valgrind but I am not looking for any invalid read/write or leaks. Valgrind will not tell me any