Skip to content

Tag: c++

Futex and pthreads issue

I’m testing futexes with pthreads. I’ve written following program: And sometimes it returns 0 as a sum which is proper value but sometimes the returned value of sum is different than 0. My question is why the returned values of “sum” are different than 0? I suspect that there is something wrong with locking but for the moment I cannot

What is the true getrusage resolution?

I’m trying to measure getrusage resolution via simple program: And when I run it, I usually get output similar to the following: ema@scv:~/tmp/getrusage$ ./gt u:0.000562 uz:0.000563 cnt:1 ema@scv:~/tmp/getrusage$ ./gt u:0.000553 uz:0.000554 cnt:1 ema@scv:~/tmp/getrusage$ ./gt u:0.000496 uz:0.000497 cnt:1 ema@scv:~/tmp/getrusage$ ./gt u:0.000475 uz:0.000476 cnt:1 Which seems to hint that the resolution of getrusage is around 1 microsecond. I thought it should be

Writing a small file blocks for 20 ms

I discovered that on my Ubuntu 22 server, attempting to write to a file, often induces around 20ms delay, even when only writing a few bytes. Here is some basic code that demonstrates the problem: And here is the output: It seems more likely to happen if there is a bit of delay between attempts, and also more likely to

Writing into a device file prints “Invalid argument”

I am currently working on a device driver where I want to write a sentence to that driver and display it in the kernel. Reading an internal buffer and calling the driver with cat works perfectly fine. However, if I try to write to the device driver it returns the following message: I have the following code for my device