monitor

Waiting for a Timer to finish in Java

流过昼夜 提交于 2019-12-29 06:06:46
问题 I'm using java.util.Timer to schedule a periodic task. At one point, I'd like to shut it down, and wait for it to finish . Timer.cancel() will prevent any future tasks from running. How do I make sure any tasks are not running at the moment (or wait for them if they are?) I can introduce external synchronization mechanisms, but I don't see how they can cover all cases. For example, if I synchronize on some Monitor within the task, I still miss the case when the task just started executing but

Waiting for a Timer to finish in Java

一曲冷凌霜 提交于 2019-12-29 06:04:07
问题 I'm using java.util.Timer to schedule a periodic task. At one point, I'd like to shut it down, and wait for it to finish . Timer.cancel() will prevent any future tasks from running. How do I make sure any tasks are not running at the moment (or wait for them if they are?) I can introduce external synchronization mechanisms, but I don't see how they can cover all cases. For example, if I synchronize on some Monitor within the task, I still miss the case when the task just started executing but

Monitor vs lock

两盒软妹~` 提交于 2019-12-27 16:39:12
问题 When is it appropriate to use either the Monitor class or the lock keyword for thread safety in C#? EDIT: It seems from the answers so far that lock is short hand for a series of calls to the Monitor class. What exactly is the lock call short-hand for? Or more explicitly, class LockVsMonitor { private readonly object LockObject = new object(); public void DoThreadSafeSomethingWithLock(Action action) { lock (LockObject) { action.Invoke(); } } public void DoThreadSafeSomethingWithMonitor(Action

Windows7.1 SDK: C2373: “MonitorFromWindow” Redefinition

佐手、 提交于 2019-12-26 12:29:10
问题 The error "linkage specification is incompatible with previous "MonitorFromWindow"" in 32 bit build VS10 MCBS is given for the following decl: int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow) { HMONITOR MonitorFromWindow(_In_ HWND hwnd, _In_ DWORD dwFlags); return DialogBoxW(hInstance, MAKEINTRESOURCEW(lpTemplate), nullptr, DlgProc); } Assumed the solution would be similar to the one given here, but here it might be some problem with the SDK

Why is `pthread_mutex_unlock` called before calling `pthread_cond_signal`?

ぐ巨炮叔叔 提交于 2019-12-25 08:50:15
问题 From The Art of Multiprocessor Programming, 1 #include <pthread.h> 2 #define QSIZE 16 3 typedef struct { 4 int buf[QSIZE]; 5 long head, tail; 6 pthread_mutex_t *mutex; 7 pthread_cond_t *notFull, *notEmpty; 8 } queue; 9 void queue_enq(queue* q, int item) { 10 // lock object 11 pthread_mutex_lock (q->mutex); 12 // wait while full 13 while (q->tail - q->head == QSIZE) { 14 pthread_cond_wait (q->notFull, q->mutex); 15 } 16 q->buf[q->tail % QSIZE] = item; 17 q->tail++; 18 // release lock 19

How to apply an effect on screen image in Windows on the fly?

痴心易碎 提交于 2019-12-25 01:29:42
问题 I'm developing a Windows application that needs to apply an effect on screen image. More specifically, I need to do the following: grab a screen image, apply a gaussian blur on it, and display it on the screen. Something similar to f.lux, only in my case the effect applied is different. Since I'm new in Windows development, I'd like to know what is the recommended way to do it? What libraries/frameworks should I use? Can you point to some code samples of similar applications? Thanks! 来源:

Monitor creation of a window (HWND)

こ雲淡風輕ζ 提交于 2019-12-25 01:10:02
问题 I would like to Monitor the creation of windows (HWND) in C. I'd like to know if there's some kind of event that the WINAPI provides to handle the creation of a window. 回答1: If you are concerned only with top-level windows, you can use SetWindowHookEx to register a ShellProc and watch for HSHELL_WINDOWCREATED . If you need notification of the creation of any window, you can use a CallWndProc and watch for WM_CREATE messages. 来源: https://stackoverflow.com/questions/7019523/monitor-creation-of

All the Swing frames get “frozen” when wait() is called in Java

≯℡__Kan透↙ 提交于 2019-12-24 14:51:25
问题 I want to wait() the put() method called from the second thread which has been connected to the Server (Monitor). But when i do this, the whole GUI frames (Swing) including their elements get frozen aftr the second put() call. How to fix this? I want the second thread keep waiting till the first thread performs a get() which frees a slot. Thanks in advance. Here's my skeleton code: Server: Buffer<String> buf = new Buffer<String>(1); while(true){ //for each socket connected new ServerHandler(.

C++ monitor running processes in the background?

本秂侑毒 提交于 2019-12-24 11:15:00
问题 I've been trying to write a program in C++ that will monitor running processes in the background and terminate a certain one if it's detected to be running. I have written a program that will do so, however the only way I can think of to do this is to use an infinite WHILE loop that keeps checking for the program. This, as you can imagine, constantly uses CPU power and resources to be constantly looping. In task manager, you can see that most processes that are running are always using 0% of

Synchronization problems with Monitor class in WCF service

僤鯓⒐⒋嵵緔 提交于 2019-12-24 05:39:22
问题 I have a self-hosted WCF service and I'm having the following problem: 15 minutes after creating the instance of the service TryEnter calls in operation contract methods constantly return false, but the TryEnter calls in Main function, which also uses synchronization via Monitor class, return true. Here's the description of my app and the bug: I am developing a self-hosted WCF service in Visual Studio 2008 (C#) in Windows XP SP2. The ServiceHost instance of the host is created at the