shared-memory

How to get memory address from shm_open?

前提是你 提交于 2019-12-25 00:21:56
问题 I want to share memory using a file descriptor with another process created via fork . The problem is that I get different address regions from mmap . I want that mmap returns the same address value. Only in such case I can be sure that I really share the memory. Probably it is possible to use MAP_FIXED flag to mmap , but how to get memory address from shm_open ? Is it possible to share memory via shm_open at all? Maybe shmget must be used instead? This is the minimal working example:

Reading shared memory from c++/c# program in java

点点圈 提交于 2019-12-24 23:12:37
问题 How can I read a shared memory section like "Global\something_something" in java that was created and is updated by a c#/c++ program? I found some tutorials, but they either work with "real files" or have some other additional stuff. I know that I have to make native calls via jna, for example, to the windows api and use something like the openFileMapping function. Are there tutorials I have missed or could someone give me a bit of example code? Is using jna or jni the only way to that sort

What stops me from reading/writing further than the size of a shared memory? (System V IPC)

无人久伴 提交于 2019-12-24 10:49:34
问题 What I'm doing is: shmget(shm_key, shm_size, 0666 | IPC_CREAT); (and of course attach to it) and I've already set the size to exactly 12 Bytes but when i try something like: sprintf(shm_ptr, "Imagine about 200-300 characters here\n"); it seems to work normally with zero problems or warnings, and to check that , I tried to read it from a completely different process (i fork and exec the first one) and sure enough printf("%s", shm_ptr); prints the message that was in that segment, which is

data visibility between threads without lock

*爱你&永不变心* 提交于 2019-12-24 07:38:40
问题 I understand the basic rules for memory ordering in C++11, especially release-acquire ordering. I have a big chunk of memory shared between two threads, where I do not need atomicity, but want to ensure that eventually all the changes done by a thread is visible in another, especially on platforms with relaxed memory model. Is it ok to simply use an atomic guard var only to trigger memory synchronization? E.g., std::atomic<bool> guardVar; char *shared_mem=get_shared_mem(); (thread 1) while

Does OpenCL allow concurrent writes to same memory address?

强颜欢笑 提交于 2019-12-24 00:49:38
问题 Is two (or more) different threads allowed to write to the same memory location in global space in OpenCL? The write is always changing a uchar from 0 to 1 so the outcome should be predictable, but I'm getting erratic results in my program, so I'm wondering if the reason can be that some of the writes fail. Could it help to declare the buffer write-only and copy it to a read-only buffer afterwards? 回答1: Did you try to use the cl_khr_global_int32_base_atomics extension and atom_inc intrinsic

Shared variables in OpenMP

橙三吉。 提交于 2019-12-24 00:38:54
问题 I have a very basic question (maybe stupid) regarding shared variables in OpenMP. Consider the following code: void main() { int numthreads; #pragma omp parallel default(none) shared(numthreads) { numthreads = omp_get_num_threads(); printf("%d\n",numthreads); } } Now the value of numthreads is the same for all threads. is there a possibility that since various threads are writing the same value to the same variable , the value might get garbled/mangled ? Or is this operation on a primitive

Would it be possible to share some memory with GNU Parallel?

给你一囗甜甜゛ 提交于 2019-12-23 23:13:33
问题 Imagine that you use gnu parallel to run several script that load every time a big object in memory, like a corpus of document for example. In the case of a read only acces to this object the question is: Can I load this object once in memory and share the read access by all the process running under Gnu Parallel ? 来源: https://stackoverflow.com/questions/34933830/would-it-be-possible-to-share-some-memory-with-gnu-parallel

Making a shared data structure in c

老子叫甜甜 提交于 2019-12-23 20:48:15
问题 I have created a data structure in my C program as follows, typedef struct { int *array; size_t used; size_t size; } Array; void initArray(Array *a, size_t initialSize) { a->array = (int *)malloc(initialSize * sizeof(int)); a->used = 0; a->size = initialSize; } void insertArray(Array *a, int element) { if (a->used == a->size) { a->size *= 2; a->array = (int *)realloc(a->array, a->size * sizeof(int)); } a->array[a->used++] = element; } void freeArray(Array *a) { free(a->array); a->array = NULL

Seeking articles on shared memory locking issues

走远了吗. 提交于 2019-12-23 17:32:13
问题 I'm reviewing some code and feel suspicious of the technique being used. In a linux environment, there are two processes that attach multiple shared memory segments. The first process periodically loads a new set of files to be shared, and writes the shared memory id (shmid) into a location in the "master" shared memory segment. The second process continually reads this "master" location and uses the shmid to attach the other shared segments. On a multi-cpu host, it seems to me it might be

How does one keep an int and an array in shared memory in C?

▼魔方 西西 提交于 2019-12-23 09:18:37
问题 I'm attempting to write a program in which children processes communicate with each other on Linux. These processes are all created from the same program and as such they share code. I need them to have access to two integer variables as well as an integer array. I have no idea how shared memory works and every resource I've searched has done nothing but confuse me. Any help would be greatly appreciated! Edit: Here is an example of some code I've written so far just to share one int but it's