Can I get Unix’s pthread.h to compile in Windows?

pthread.h is a header for the Unix/Linux (POSIX) API for threads. A POSIX layer such as Cygwin would probably compile an app with #include <pthreads.h>. The native Windows threading API is exposed via #include <windows.h> and it works slightly differently to Linux’s threading. Still, there’s a replacement “glue” library maintained at http://sourceware.org/pthreads-win32/ ; note that it has some slight incompatibilities with … Read more

Still Reachable Leak detected by Valgrind

There is more than one way to define “memory leak”. In particular, there are two primary definitions of “memory leak” that are in common usage among programmers. The first commonly used definition of “memory leak” is, “Memory was allocated and was not subsequently freed before the program terminated.” However, many programmers (rightly) argue that certain … Read more

Program received signal SIGPIPE, Broken pipe

The process received a SIGPIPE. The default behaviour for this signal is to end the process. A SIGPIPE is sent to a process if it tried to write to a socket that had been shutdown for writing or isn’t connected (anymore). To avoid that the program ends in this case, you could either make the process ignore SIGPIPE#include <signal.h> … Read more

How to print pthread_t

This will print out a hexadecimal representation of a pthread_t, no matter what that actually is: To just print a small id for a each pthread_t something like this could be used (this time using iostreams): Depending on the platform and the actual representation of pthread_t it might here be necessary to define an operator< for pthread_t, because std::map needs an ordering on the elements:

Undefined reference to pthread_create in Linux

I picked up the following demo off the web from https://computing.llnl.gov/tutorials/pthreads/ But when I compile it on my machine (running Ubuntu Linux 9.04) I get the following error: This doesn’t make any sense to me, because the header includes pthread.h, which should have the pthread_create function. Any ideas what’s going wrong?