thread-safety

Safe to use volatile bool to force another thread to wait? (C++)

烂漫一生 提交于 2019-12-21 04:17:24
问题 Everything I've read about volatile says it's never safe, but I still feel inclined to try it, and I haven't seen this specific scenario declared unsafe. I have a separate thread that renders a scene, pulling data from the main simulation thread. This has no synchronization, and works fine. The issue is that when the program exits, then renderer needs to stop pulling data from the simulation thread before the simulation thread can safely clean itself up without causing the renderer to attempt

Spring AOP and aspect thread safety for an autowired HTTPServletRequest bean

左心房为你撑大大i 提交于 2019-12-21 04:05:25
问题 I am using Spring 3 AOP, and I have an aspect that requires access to the HttpServletRequest. It looks something like this: @Aspect public class MyAspect { @Autowired private HttpServletRequest httpServletRequest; public void init() { // Do something once... } @Before("my pointcut here...") private void myMethod() { // I need the httpServletRequest... } @After("my pointcut here...") private void myOtherMethod() { // I need the httpServletRequest... } } And is configured like this: <bean id=

Query whether Python's threading.Lock is locked or not

做~自己de王妃 提交于 2019-12-21 03:37:05
问题 I have a thread I am running (code below) which launches a blocking subprocess. To ensure that other threads do not launch the same subprocess, I have a lock around this subprocess.call call. I also want to be able to terminate this subprocess call, so I have a stop function which I call from somewhere else. In the event that the subprocess is stopped prematurely, I want to release the lock as well, which is what the below code does: class SomeThread(threading.Thread): def run(self): aLock

Using 'HttpContext.Current.Cache' safely

折月煮酒 提交于 2019-12-21 03:33:31
问题 I am using Cache in a web service method like this: var pblDataList = (List<blabla>)HttpContext.Current.Cache.Get("pblDataList"); if (pblDataList == null) { var PBLData = dc.ExecuteQuery<blabla>(@"SELECT blabla"); pblDataList = PBLData.ToList(); HttpContext.Current.Cache.Add("pblDataList", pblDataList, null, DateTime.Now.Add(new TimeSpan(0, 0, 15)), Cache.NoSlidingExpiration, CacheItemPriority.Normal, null); } But I wonder, is this code thread-safe? The web service method is called by

Thread safe programming

旧街凉风 提交于 2019-12-21 02:21:08
问题 I keep hearing about thread safe. What is that exactly and how and where can I learn to program thread safe code? Also, assume I have 2 threads, one that writes to a structure and another one that reads from it. Is that dangerous in any way? Is there anything I should look for? I don't think it is a problem. Both threads will not (well can't ) be accessing the struct at the exact same time.. Also, can someone please tell me how in this example : https://stackoverflow.com/a/5125493/1248779 we

Searching on a Background Thread

Deadly 提交于 2019-12-21 01:46:06
问题 I am trying to search through a few thousand objects in my iPhone app, however the search lags badly - after each keystroke the UI freezes for 1 - 2 seconds. To prevent this, I have to execute the search on a background thread. I was wondering whether anyone had some tips for searching on a background thread? I read a little into NSOperation and searched the web, but didn't really find anything useful. 回答1: Try using an NSOperationQueue as an instance variable in your view controller.

Creating a thread-safe temporary file name

ε祈祈猫儿з 提交于 2019-12-20 17:38:59
问题 When using Tempfile Ruby is creating a file with a thread-safe and inter-process-safe name. I only need a file name in that way. I was wondering if there is a more straight forward approach way than: t = Tempfile.new(['fleischwurst', '.png']) temp_path = t.path t.close t.unlink 回答1: Dir::Tmpname.create You could use Dir::Tmpname.create . It figures out what temporary directory to use (unless you pass it a directory). It's a little ugly to use given that it expects a block: require 'tmpdir' #

No enclosing instance of type is accessible. [duplicate]

こ雲淡風輕ζ 提交于 2019-12-20 14:14:29
问题 This question already has answers here : Java - No enclosing instance of type Foo is accessible (5 answers) Closed 6 years ago . The whole code is: public class ThreadLocalTest { ThreadLocal<Integer> globalint = new ThreadLocal<Integer>(){ @Override protected Integer initialValue() { return new Integer(0); } }; public class MyThread implements Runnable{ Integer myi; ThreadLocalTest mytest; public MyThread(Integer i, ThreadLocalTest test) { myi = i; mytest = test; } @Override public void run()

Why use tensorflow gfile? (for file I/O)

£可爱£侵袭症+ 提交于 2019-12-20 12:06:28
问题 Tensorflow code uses methods for file I/O that are different than python builtin methods. According to the source code, it is useful as "File I/O wrappers without thread locking" I am not sure on what occasions it is useful and when it shouldn't be used. Any idea? Thank you 回答1: This comment: File I/O wrappers without thread locking ...is a particularly unhelpful description for TensorFlow's tf.gfile module! The main roles of the tf.gfile module are: To provide an API that is close to Python

Is the max thread limit actually a non-relevant issue for Python / Linux?

百般思念 提交于 2019-12-20 11:56:09
问题 The current Python application that I'm working on has a need to utilize 1000+ threads (Pythons threading module). Not that any single thread is working at max cpu cycles, this is just a web server load test app I'm creating. I.E. emulate 200 firefox clients all longing into web server and downloading small web components, basically emulating humans that operate in seconds as opposed to microseconds. So, I was reading through the various topics such as "how many threads does python support on