thread-safety

Functional way to implement a thread safe shared counter

一世执手 提交于 2020-01-12 08:02:11
问题 I'm relatively new to Scala and functional programming, and I like the idea that using immutable objects I can avoid many thread safety pitfalls. One thing still haunts me, and it's the classical example used to teach thread safety - the shared counter. I was wondering if it would be possible to implement a thread-safe counter (a request counter in this example), using immutable objects, and functional concepts, and avoid synchronization completely. So for reference here are first the

thread safety of read/pread system calls

孤人 提交于 2020-01-12 07:36:35
问题 I have few queries related to read()/pread() system calls in a multithreaded environment I am using Mac-OSX which is freeBsd based , if that helps in any way I am only using this file in read mode,and not read/write And the language is c/c++ Suppose we have a file on disk AAAABBBBCCCCDDDEEEE.... and 4 alphabets fit on one page of the file So Page1:AAAA Page2:BBBB ..... and so on now i initiate a read system call from two different threads with the same file descriptor my intension is to read

thread safety of read/pread system calls

感情迁移 提交于 2020-01-12 07:36:09
问题 I have few queries related to read()/pread() system calls in a multithreaded environment I am using Mac-OSX which is freeBsd based , if that helps in any way I am only using this file in read mode,and not read/write And the language is c/c++ Suppose we have a file on disk AAAABBBBCCCCDDDEEEE.... and 4 alphabets fit on one page of the file So Page1:AAAA Page2:BBBB ..... and so on now i initiate a read system call from two different threads with the same file descriptor my intension is to read

Lightweight spinlocks built from GCC atomic operations?

岁酱吖の 提交于 2020-01-12 04:40:13
问题 I'd like to minimize synchronization and write lock-free code when possible in a project of mine. When absolutely necessary I'd love to substitute light-weight spinlocks built from atomic operations for pthread and win32 mutex locks. My understanding is that these are system calls underneath and could cause a context switch (which may be unnecessary for very quick critical sections where simply spinning a few times would be preferable). The atomic operations I'm referring to are well

Easy way to excecute method after a given delay?

放肆的年华 提交于 2020-01-11 19:56:26
问题 Is there a easy way to perform a method after a given delay like in iOS out of the box? On iPhone I would do this: [self performSelector:@selector(connectSensor) withObject:nil afterDelay:2.5]; It will then schedule the method connectSensor on the main thread (UI thread) to be executed after 2,5 seconds. And because it is automatically scheduled on the main thread, you don't have to worry about cross thread issues. (There is also a performSelectorOnBackground version) So how would I do this

Easy way to excecute method after a given delay?

瘦欲@ 提交于 2020-01-11 19:55:34
问题 Is there a easy way to perform a method after a given delay like in iOS out of the box? On iPhone I would do this: [self performSelector:@selector(connectSensor) withObject:nil afterDelay:2.5]; It will then schedule the method connectSensor on the main thread (UI thread) to be executed after 2,5 seconds. And because it is automatically scheduled on the main thread, you don't have to worry about cross thread issues. (There is also a performSelectorOnBackground version) So how would I do this

ASyncTasks blocking others

陌路散爱 提交于 2020-01-11 15:49:41
问题 I've 2 ASyncTasks, one retrieves a value from an httpPost and the other update some elements of the UI (including an listview). The problem is that since both ASyncTasks share the same background thread, if the network opperation start first and runs slow (due a bad network connectivity). The others background thread takes too much time making the app irresponsible. Since both ASyncTasks are independient is pretty stupid one to make wait the other. It would be more logical asynctasks

ASyncTasks blocking others

孤者浪人 提交于 2020-01-11 15:49:09
问题 I've 2 ASyncTasks, one retrieves a value from an httpPost and the other update some elements of the UI (including an listview). The problem is that since both ASyncTasks share the same background thread, if the network opperation start first and runs slow (due a bad network connectivity). The others background thread takes too much time making the app irresponsible. Since both ASyncTasks are independient is pretty stupid one to make wait the other. It would be more logical asynctasks

NHibernate thread safety with session

流过昼夜 提交于 2020-01-11 15:30:28
问题 I've been using NHibernate for a while now and have found from time to time that if I try to request two pages simultaniously (or as close as I can) it will occasionally error. So I assumed that it was because my Session management was not thread safe. I thought it was my class so I tried to use a different method from this blog post http://pwigle.wordpress.com/2008/11/21/nhibernate-session-handling-in-aspnet-the-easy-way/ however I still get the same issues. The actual error I am getting is:

Partially thread-safe dictionary

不羁岁月 提交于 2020-01-11 10:07:13
问题 I have a class that maintains a private Dictionary instance that caches some data. The class writes to the dictionary from multiple threads using a ReaderWriterLockSlim . I want to expose the dictionary's values outside the class. What is a thread-safe way of doing that? Right now, I have the following: public ReadOnlyCollection<MyClass> Values() { using (sync.ReadLock()) return new ReadOnlyCollection<MyClass>(cache.Values.ToArray()); } Is there a way to do this without copying the collection