posix

Periodic thread fails real-time in Xenomai

我与影子孤独终老i 提交于 2019-12-22 18:01:40
问题 I'm creating a periodic thread which outputs a square signal on an analogic output. I'm using Posix Skin and Analogy from the Xenomai API. I tested the real-time performance of my code using an oscilloscope and looking at the latency on the square signal (whose frequency is 1kHz). I am supposed to achieve <100us latency. However, the signal is strongly (>250us latency) perturbated by common interruption signals, like moving the mouse, starting a new program, etc. The flags in my makefile are

pthread_cond_signal() release exactly one thread?

ⅰ亾dé卋堺 提交于 2019-12-22 13:01:24
问题 Does pthread_cond_signal unblock exactly one thread? If not, what will be the case it releases more than one thread? The specification says as follows: The pthread_cond_signal() function shall unblock at least one of the threads that are blocked on the specified condition variable cond (if any threads are blocked on cond). 回答1: The pthreads specification allows for "spurious wakeups" in an implementation. See, for example, the hypothetical implementation of pthread_cond_signal and pthread

pthread_cond_signal() release exactly one thread?

天大地大妈咪最大 提交于 2019-12-22 12:59:26
问题 Does pthread_cond_signal unblock exactly one thread? If not, what will be the case it releases more than one thread? The specification says as follows: The pthread_cond_signal() function shall unblock at least one of the threads that are blocked on the specified condition variable cond (if any threads are blocked on cond). 回答1: The pthreads specification allows for "spurious wakeups" in an implementation. See, for example, the hypothetical implementation of pthread_cond_signal and pthread

Boost: How to print/convert posix_time::ptime in milliseconds from Epoch?

倾然丶 夕夏残阳落幕 提交于 2019-12-22 10:11:01
问题 I am having trouble converting posix_time::ptime to a timestamp represented by time_t or posix_time::milliseconds , or any other appropriate type which can be easily printed (from Epoch). I actually need just to print the timestamp represented by the posix_time::ptime in milliseconds, so if there is an easy way to print in that format, I don't actually need the conversion. 回答1: This code will print the number of milliseconds since 1941-12-07T00:00:00. Obviously, you can choose whatever epoch

Understanding posix barrier mechanism

∥☆過路亽.° 提交于 2019-12-22 09:43:07
问题 Here is piece (very simplified, with global var's and other "smells") of C code, which uses posix barrier primitive to sincronize thread start. #include <pthread.h> #include <stdio.h> pthread_barrier_t barrier; void* thread_func(void* aArgs) { pthread_barrier_wait(&barrier); printf("Entering thread %p\n", (void*)pthread_self()); int i; for(i = 0 ; i < 5; i++) printf("val is %d in thread %p \n", i, (void*)pthread_self()); } int main() { pthread_t thread_1, thread_2; pthread_barrier_init(

Maximum hostname length on Linux

淺唱寂寞╮ 提交于 2019-12-22 09:11:27
问题 I am gathering the hostnames of all nodes in an mpi application. I'm using gethostname and I want to ensure I have enough space to store the resulting string. I'm specifically avoiding MPI's getprocessorname as I want the machine's name and I don't want to have to parse it from that. There appear to be two options, bits/local_lim.h:#define HOST_NAME_MAX 64 bits/posix1_lim.h:#define _POSIX_HOST_NAME_MAX 255 What are the advantages of each? Should I include one of these headers directly or is

How should a backslash resulting from variable expansion be treated?

北城以北 提交于 2019-12-22 08:35:28
问题 I ran the following command ( *sh being the name of a sh implementation) with all the shells I could find; although I was expecting all to print match , I got inconsistent results. I don't know which behavior is correct and reliable. *sh -c 'case "$1" in $2) echo match; esac' _ 'f\oo' 'f\\oo' With dash from Ubuntu bionic's repo (and ash; which is a symbolic link to dash) $ dash -c 'case "$1" in $2) echo match; esac' _ 'f\oo' 'f\\oo' match With bash 4.4.20(1)-release (x86_64-pc-linux-gnu) and

POSIX queues and msg_max

时光毁灭记忆、已成空白 提交于 2019-12-22 08:18:54
问题 I am toying a bit with POSIX queues and I encountered a problem. When creating a new queue I can specify for example the size of the message and how many messages there can be in the queue. My normal limit is 10 as found in /proc/sys/fs/mqueue/msg_max is there an easy way to change it during program execution, apart from echo number > /proc/sys/fs/mqueue/msg_max maybe some system call for setting such things exists. 回答1: No. That limit is a system-wide limit; that's why it's in /proc/sys . If

How to set the terminal's size?

為{幸葍}努か 提交于 2019-12-22 08:15:19
问题 How do I get the terminal size in Go. In C it would look like this: struct ttysize ts; ioctl(0, TIOCGWINSZ, &ts); But how to i access TIOCGWINSZ in Go 回答1: The cgo compiler can't handle variable arguments in a c function and macros in c header files at present, so you can't do a simple // #include <sys/ioctl.h> // typedef struct ttysize ttysize; import "C" func GetWinSz() { var ts C.ttysize; C.ioctl(0,C.TIOCGWINSZ,&ts) } To get around the macros use a constant, so // #include <sys/ioctl.h> //

Write/Read to/from FIFO files - linux

谁都会走 提交于 2019-12-22 07:44:31
问题 I've been trying to wrap my head around FIFO, and came up with a simple program of server and client. I'm not trying to do anything fancy, just to have one process that will play a role of 'server', this process will 'listen' to any messages delivered by another process; the client. Here's what I wrote: server.c #include<stdio.h> #include <fcntl.h> #include <stdlib.h> #define INGOING "clientToServer.fifo" #define BUFFER 200 int main(int argc, char *argv[]) { char in[BUFFER]; mkfifo(INGOING,