天道酬勤,学无止境

thread-safety

Is createTempFile thread-safe?

I'm using Java 6. Is it possible that two threads calling createTempFile (of the class java.io.File) get the same temp file?

2021-06-21 10:57:21    分类:问答    java   file-io   thread-safety   temporary-files

Is boost::interprocess threadsafe?

Currently, I have 2 processes that communicate using the message_queue and shared_memory form boost. Everything work as attended. Now I need to make one of this process multi threaded (thanks to boost again), and I was wondering if I need to use protection mechanism between the threads (such as mutex), or if the boost::interprocess library already provides a protection mechanism ? I did not find any info on that on the boost documentation. By the way I'm using boost 1.40. Thanks in advance.

2021-06-21 10:25:25    分类:问答    c++   boost   thread-safety   boost-interprocess

std::ifstream 线程安全且无锁吗?(Is std::ifstream thread-safe & lock-free?)

问题 我打算使用 std::ifstream 执行打开以从多个线程读取单个文件。 我担心的是 std::ifstream 是否是线程安全和无锁的? 更多细节: 我在 Ubuntu 和 Windows XP 上使用 g++ 4.4,在 Leopard 上使用 4.0。 每个线程创建自己的 std::ifstream 实例 提前致谢! 回答1 那是实现定义。 标准 C++ 对线程没有任何说明,因此任何关于线程的假设本质上都会调用未指定的或实现定义的行为。 我们需要您使用的平台更加具体,但假设 ifstream 是线程安全的或无锁的可能是不合理的。 如果不出意外,操作系统级调用中可能会涉及到实际从文件中读取的锁,在这种情况下,不可能实现真正的无锁实现。 即使没有,每次从 ifstream 中读取都需要检查多个格式标志,并且需要根据读取过程中发生的情况更新标志位。 (即istream::good()和istream::operator bool )由于无法原子地完成所有这些,因此对istream的线程安全特性进行过多假设是不合理的。 回答2 请参阅 http://gcc.gnu.org/onlinedocs/libstdc++/manual/using_concurrency.html。 在编写该手册页时,GCC 的标准库遵从操作系统的 C stdio 文件缓冲。 它们避免将状态保持在 C

2021-06-21 09:20:10    分类:技术分享    c++   thread-safety   ifstream   lock-free   file-locking

Convert wait & notifyAll code to use Java 1.5 Lock object

We use code that uses syncronized blocks around segments of code with a lot of wait and notifyAll() calls. We are trying to convert these to use Java 5 Lock.lock() and Lock.unlock() methods. How do I migrate this code to remove all the wait and notifyAll calls. I do not know the equivalent to these using the new Locking features. Any links with examples would be appreciated. Thanks in Advance Eq., the following code needs to be converted to use Lock.lock() and lock.unlock The first part to remove the synchronized block is simple as I just need to call lock() method. The question is what can be

2021-06-15 17:57:38    分类:问答    java   multithreading   concurrency   thread-safety

Function local static function-object that's initialized by lambda, thread-safe or not?

Is the following function thread-safe? And if it's not thread-safe, then is there really any overhead in making that funImpl non-static? Or does the compiler actually inline that function-object function and skip creating the function object altogether? int myfun(std::array<int, 10> values) { static const auto funImpl = [&]() -> int { int sum = 0; for (int i = 0; i < 10; ++i) { sum += values[i]; } return sum; }; return funImpl(); } EDIT: I edited the function signature from: int myfun(const std::array<int, 10>& values) to: int myfun(std::array<int, 10> values) so that it is clear that I'm not

2021-06-15 14:32:05    分类:问答    c++   static   lambda   c++11   thread-safety

Is Extension method thread safe?

Is this Extension method thread safe? public static class Extensions { public static void Raise<T>(this EventHandler<T> handler, object sender, T args) where T : EventArgs { if (handler != null) handler(sender, args); } } or do I need to change it to this? public static class Extensions { public static void Raise<T>(this EventHandler<T> handler, object sender, T args) where T : EventArgs { var h = handler; if (h!= null) h(sender, args); } }

2021-06-15 12:05:47    分类:问答    c#   thread-safety   extension-methods

JavaFX: How can I use correctly a ProgressIndicator in JavaFX

I´m newbe in JavaFX. I have a problem with my JavaFX application, I need to start my ProgressIndicator (type INDETERMINATE) before a database query. This is part of my code: spinner.setVisible(true); passCripto = cripto.criptoPass(pass); MyDao dao = new MyDaoImpl(); boolean isLoginOk = dao.isUserOk(user, passCripto); boolean isStatusOk = dao.idStatusUser(user); When finished, I need to set spinner to FALSE but the spinner only is showed when database query is finished. How can I solve this ? Thanks. I do this, but not resolved: Task<Boolean> taskValidaLogin = new Task<Boolean>() { @Override

2021-06-15 11:43:53    分类:问答    java   thread-safety   task   javafx-8

Lucene QueryParser in multiple threads: synchronize or construct new each time?

I have a web application where users submit queries to a Lucene index. The queries are parsed by a Lucene QueryParser. I learned the hard way that QueryParser is not thread-safe. Is it better to use a single QueryParser instance, and synchronize on calls to its parse() method? Or is it better to construct a new instance for each query? (Or would I be better served by a pool of QueryParsers?) I know that in general questions like this depend on the particulars and require profiling, but maybe someone out there can say definitively "QueryParsers are extremely inexpensive/expensive to construct"?

2021-06-15 10:12:59    分类:问答    java   lucene   thread-safety   query-parser

How do I atomically read a value in x86 ASM?

I know how to atomically write a value in x86 ASM. But how do I read one? The LOCK prefix can't be used with mov. To increase a value, I am doing: lock inc dword ptr Counter How do I read Counter in a thread-safe way?

2021-06-15 08:48:42    分类:问答    assembly   x86   thread-safety   atomic

AsyncTask thread still there after execute, is that normal?

when I use AsyncTasks checking in the DDMS, the thread persist in memory as waiting thread after the onPostExecute() method, is that normal?. Here is a simplified Activity that reproduces my problem: package com.example.async; import android.app.Activity; import android.content.Intent; import android.os.AsyncTask; import android.os.Bundle; import android.util.Log; public class ASyncTaskExampleActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main)

2021-06-15 07:24:41    分类:问答    java   android   multithreading   thread-safety   android-asynctask