this is my code: there is a while loop in the wait function of a semaphore, can’t I use an if statement simply? Answer Because we can’t assume that after a thread is woken up and it requires the lock another thread has not already come along and taken the resource this is guarding:
Tag: c++
D-Bus returns UnkownMethod – saying No such interface on object at path
I want to write a short program, which triggers the Thumbnail creation for all pictures on my network share recursively (e.g. over night) – so that when I access a folder in Thunar, the thumbs are displayed immediately. I would say, that when I can access the API via gdbus call, then the system is setup correctly: But when I
Read number from stdin and save as integer directly, using read() function
when I execute this code, it returns just random integer like 724109877 Why this happend? also glad to hear if someone tells me right way to read number from stdin and save as integer Answer You can do that by reading a line and convert it to a number later: Note that nb_bytes will include the newline character, you can
C++: How can statvfs take a structure of its own type as an input?
I am using statvfs to check the filesystem, and I have difficulties understanding how the following snippet works: I include the header. This is the only line that’s 100% clear to me here. I make aStructure of the type statvfs. I call statvfs with aPath and the structure from the previous step. In 2. statvfs was a structure, in 3.
Organize multitrheading datalogging [closed]
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 2 years ago. Improve this question I’m working on a C project for an embedded target running a Linux distribution (build with Yocto). I’m new to Linux embedded world and I
Measuring Elapsed Time Using clock_gettime(CLOCK_MONOTONIC)
I have to elapse the measuring time during multiple threads. I must get an output like this: Firstly, I used gettimeofday but I saw that there are some negative numbers then I made little research and learn that gettimeofday is not reliable to measure elapsed time. Then I decide to use clock_gettime(CLOCK_MONOTONIC). However, there is a problem. When I use
C: getopt_long() always returns invalid option
I’m trying to add a new option to an already working C program using getopt_long. The option I want to add is -S but every time I try to run the code I get: I simply add a new element to long_options vector concerning the option I want to add in this way: Below there is my code: I tried
Is there a linux equivalent of _aligned_realloc
Is there a linux equivalent of _aligned_realloc? I want to use realloc so I don’t have to memcpy the data every time I resize it. Am I stuck with mmap? I only used mmap once is there a recommended way of implementing memory that will be resized a few times? I’m assuming I can’t mix mmap with aligned_alloc and I
Get Character String Written to Custom /dev/ file
I’m currently working with a custom device driver that I installed. I’m very new to this and having trouble understanding how to get the data that I write into it from the command line. For example, I write data to the file like so: And then I merely want to get the string here, so I can use the characters
(Socket operation on non socket) error while trying to receive data on a TCP server
What I want to do is send a message (which I type on the terminal) from the client to the server. I’m getting this error on the server when I try to call the recv() function. As you can see, the client doesn’t show errors. This is the code I’ve written for the server side: I’m confused because I’m already