I was reading source code of glibc. In function void *__libc_malloc(size_t bytes): It shows that if the first thread was created, it calls ptmalloc_init(), and links thread_arena with main_arena, and sets __malloc_initialized to true. On the other hand, the second thread was blocked by the following code in ptmalloc_init(): Thus the thread_arena of the second thread is NULL, and it
Tag: malloc
Data gets distorted which is printed in loop
Facing issue when printing the data that is updated in malloc. In the below code am creating a string Test.DataType_1.Tag_1 …. Test.DataType_1.Tag_20 in create_tags() function, when the data is updated properly and printed i create_tags() function it prints properly but if printed in main() function in for loop data is distorted. The output of the code is follows, when i
Error in malloc while trying to create a thread
Hi everyone i post only the core of the code which create probleam and which work with threads. As we can see foo function create new thread and reallocate memory to store the pthread_t. Then it try to create a new thread with pthread_create as NULL as attr and arg and as function pointer a pointer to foo2; Now the
Do linux read/write system calls use dynamic memory allocation?
I wonder if read and write system calls on linux (used with unix sockets) do dynamic memory allocation? The context are real time applications and deterministic behaviour. Answer No. If you look for syscalls in the Linux kernel source (I used grep -rn SYSCALL_DEFINE.*write to find read/write), you can see the source for yourself: Note that system call definitions can
Understanding glibc malloc trimming
Some program that I am currently working on consumes much more memory than I think it should. So I am trying to understand how glibc malloc trimming works. I wrote the following test: Test output (without calling malloc_trim): Even though almost all memory was released, this test code consumes much more resident memory than expected: Process smaps: When I enable
Reuse char * pointer needs to free and malloc again?
I would like to implement a main function such as in order to execute system commands. The following code is currently used : Because I need to enter other commands, I am currently using the same cmd_buffer by using free() before reallocating memory. Is it the right way to do ? Some other commands might be required in the future.
Is malloc deterministic?
Is malloc deterministic? Say If I have a forked process, that is, a replica of another process, and at some point both of them call the malloc function. Would the address allocated be the same in both processes? Assuming that other parts of execution are also deterministic. Note: Here, I’m only talking about virtual memory, not physical one. Answer There