shared-memory

wait and notify in C/C++ shared memory

我怕爱的太早我们不能终老 提交于 2019-11-28 17:28:24
How to wait and notify like in Java In C/C++ for shared memory between two or more thread?I use pthread library. Instead of the Java object that you would use to wait/notify, you need two objects: a mutex and a condition variable. These are initialized with pthread_mutex_init and pthread_cond_init . Where you would have synchronized on the Java object, use pthread_mutex_lock and pthread_mutex_unlock (note that in C you have to pair these yourself manually). If you don't need to wait/notify, just lock/unlock, then you don't need the condition variable, just the mutex. Bear in mind that mutexes

Is C++11 atomic<T> usable with mmap?

隐身守侯 提交于 2019-11-28 17:06:49
问题 I want to add network control of a handful of parameters used by a service (daemon) running on a Linux embedded system. There's no need for procedure calls, each parameter can be polled in a very natural way. Shared memory seems a nice way to keep networking code out of the daemon, and limit shared access to a carefully controlled set of variables. Since I don't want partial writes to cause visibility of values never written, I was thinking of using std::atomic<bool> and std::atomic<int> .

Shared Memory or mmap - Linux C/C++ IPC

纵饮孤独 提交于 2019-11-28 16:52:27
问题 The context is Inter-Process-Communication where one process("Server") has to send fixed-size structs to many listening processes("Clients") running on the same machine. I am very comfortable doing this in Socket Programming. To make the communication between the Server and the Clients faster and to reduce the number of copies, I want to try out using Shared Memory(shm) or mmaps. The OS is RHEL 64bit. Since I am a newbie, please suggest which should I use. I'd appreciate it if someone could

Delete all SYSTEM V shared memory and semaphores on UNIX-like systems

混江龙づ霸主 提交于 2019-11-28 16:43:56
问题 How can I delete all not used semaphores and shared memory with a single command on a UNIX-like system, e.g., Ubuntu? 回答1: Here, save and try this script (kill_ipcs.sh) on your shell: #!/bin/bash ME=`whoami` IPCS_S=`ipcs -s | egrep "0x[0-9a-f]+ [0-9]+" | grep $ME | cut -f2 -d" "` IPCS_M=`ipcs -m | egrep "0x[0-9a-f]+ [0-9]+" | grep $ME | cut -f2 -d" "` IPCS_Q=`ipcs -q | egrep "0x[0-9a-f]+ [0-9]+" | grep $ME | cut -f2 -d" "` for id in $IPCS_M; do ipcrm -m $id; done for id in $IPCS_S; do ipcrm

MPI vs openMP for a shared memory

∥☆過路亽.° 提交于 2019-11-28 16:21:24
问题 Lets say there is a computer with 4 CPUs each having 2 cores, so totally 8 cores. With my limited understanding I think that all processors share same memory in this case. Now, is it better to directly use openMP or to use MPI to make it general so that the code could work on both distributed and shared settings. Also, if I use MPI for a shared setting would performance decrease compared with openMP? 回答1: With most distributed memory platforms nowadays consisting of SMP or NUMA nodes it just

Efficiently applying a function to a grouped pandas DataFrame in parallel

谁都会走 提交于 2019-11-28 15:35:26
问题 I often need to apply a function to the groups of a very large DataFrame (of mixed data types) and would like to take advantage of multiple cores. I can create an iterator from the groups and use the multiprocessing module, but it is not efficient because every group and the results of the function must be pickled for messaging between processes. Is there any way to avoid the pickling or even avoid the copying of the DataFrame completely? It looks like the shared memory functions of the

What's the difference between the message passing and shared memory concurrency models?

£可爱£侵袭症+ 提交于 2019-11-28 15:17:31
问题 Correct me if I'm wrong, but I'm surprised this hasn't been asked before on here ... 回答1: It's a pretty simple difference. In a shared memory model, multiple workers all operate on the same data. This opens up a lot of the concurrency issues that are common in parallel programming. Message passing systems make workers communicate through a messaging system. Messages keep everyone seperated, so that workers cannot modify each other's data. By analogy, lets say we are working with a team on a

Is it safe to serialize a raw boost::variant?

最后都变了- 提交于 2019-11-28 11:27:55
boost::variant claims that it is a value type. Does this mean that it's safe to simply write out the raw representation of a boost::variant and load it back later, as long as it only contains POD types? Assume that it will be reloaded by code compiled by the same compiler, and same version of boost, on the same architecture. Also, (probably) equivalently, can boost::variant be used in shared memory? Regarding serialisation: It should work, yes. But why don't you use boost::variant 's visitation mechanism to write out the actual type contained in the variant? struct variant_serializer : boost:

pthread Thread objects reset their state

拜拜、爱过 提交于 2019-11-28 11:19:00
Working recently with the extension pthreads , i discovered an anomaly. I have a simple object with an internal state: class Sum { private $value = 0; public function add($inc) { $this->value += $inc; } public function getValue() { return $this->value; } } Now i created a Thread class that does something with this object: class MyThread extends Thread { private $sum; public function __construct(Sum $sum) { $this->sum = $sum; } public function run(){ for ($i=0; $i < 10; $i++) { $this->sum->add(5); echo $this->sum->getValue() . " "; } } } In my main function i created a Sum object, injected it

How can I store data in RAM memory using PHP?

萝らか妹 提交于 2019-11-28 09:20:09
Is there a way to store small data in RAM memory using PHP so that I can have access to the data between different session instead of regenerating it. Something similar to memcached (I don't have access to memcahced). My current solution is just to save the data in file. APC ? It works differents from memcached; in memcached you can access the data from various languages (c, python, etc..) while APC works only for PHP. EDIT are you sure that APC is installed correctly? Did you add extension=apc.so in your php.ini? And to restart apache (im assuming youre on a lamp server with apache2)? What