Why is the lock activated by XInitThreads non-recursive? - x11

Consider the following call flow:
Function A calls XCheckIfEvent passing a pointer to function B in the predicate parameter. Function B calls XGetWindowProperty.
If XLib is initialized with the XInitThreads function, the above call flow hangs at the call to XGetWindowProperty. It seems to me that the lock which is activated when XInitThreads is called is not recursive. If true, why? Is there a way to make it recursive? Or is it officially prohibited to call XLib functions from within a callback passed to an XLib function?

From the man page:
If Xlib has been initialized for threads, the predicate is called with
the display locked and the result of a call by the predicate to any
Xlib function that locks the display is not defined unless the caller
has first called XLockDisplay.
From the other man page:
Nested calls to XLockDisplay work correctly
So it seems that the predicate must call XLockDisplay, and XUnlockDisplay when it's done.

Related

How can warm start a method in TwinCAT?

One of the features of the method based on the definition of Beckoff site is that:
All data of a method are temporary and are only valid while the method
is executed (stack variables). This means that TwinCAT re-initializes
all variables and function blocks, which you have declared in a
method, with each call of the method.
Is there any way to use a method in the plc loop as warm start!
it means that we use the method without re_initializing and method declare variations run just once at the first time we call it and the rest of the time that is called the variables retain their own values?
Yes, this is possible through VAR_INST or VAR_STAT.
Just declare your variables as VAR_INST/VAR_STAT instead, then they will retain their values between the calls.
VAR_INST means it will be unique for every instantiation of the function block of where the method resides, while VAR_STAT will act as a static/global (all instances will point to the same memory location).
https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_plc_intro/2528798091.html&id=
https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_plc_intro/2528787339.html&id=

cocos2d-x write the callbacks using c++11 lambda

sometimes the usage of a callback is very limited, which makes it in-appropriate to be a member function. so at these times I always want to write the event call backs as lambda functions as the usage is limited the codeblock is compact if wrote in lambda
but this callback is generally defined member functions and there are interface limitations inforced on it
I wonder if it is possbile to rewrite the callback in lambda functions ?
pMenuOK->setTarget(this,menu_selector(PlayerLayer::onPlayed));
void PlayerLayer::onPlayed(cocos2d::CCObject *pSender);
For simple CCCallFunc callbacks that take no parameters, you may want to check out
MCBCallLambda.
I don't think it's possible. The way they are called by Cocos2d-x is by using a target pointer to a CCObject in combination with a method pointer. Thus, the target has to be a CCObject. As you said, these are defined for different types of parameters. Cocos2d-x need to be changed to support this.
It is possible for any method that accepts CCCallFunc [1] or its subclasses. Create own subclass of CCCallFunc which keeps std::function and overrides execute method and maybe some other methods (figure out which implementation needed from CCCallFunc sources).
[1] http://www.cocos2d-x.org/embedded/cocos2d-x/dd/d6e/classcocos2d_1_1_c_c_call_func.html

Xcode won't run or step into one of my called methods

I'm not sure what's expected for me to leave here, but basically, I've passed an object of type AwesomeMenu into an ActionControl object's (subclass of NSOBject) initializer class so that the ActionControl object has a reference to the AwesomeMenu. However, in one of the ActionControl functions, there is a call like
[self.menu updateButton];
Where self.menu is the AwesomeMenu and updateButton is a function within AwesomeMenu. For some reason, XCode never enters updateButton. I've tried setting up breakpoints inside updateButton. They don't ever trip. I tried stepping INTO updateButton (it just shows me the parameters and then it skips past the line without taking me into the function), etc. I don't get any errors either. My chosen path through the program takes me over that function call multiple times but it never actually calls.
What's happening?
I did not assign self.menu prior to calling one of its functions; self.menu's value was nil. I just had to switch my initialization statements around to get it to work.

Event handler and functions are the same thing?

As per my understanding, unlike functions, event handler receives the event object as parameter.
Is there any other difference between those two words or both are similar?
Can anyone elaborate both the terms?
It really depends on the specific language and API you are using. In C for instance, event-handlers are usually implemented as functions. in C++ they can also be callable objects. Other languages may offer different options.
It may depend on the language. Event handler is a function which often has a special parameter (in most cases) where the parameter is the event object.
So no, there's really no difference between an event handler and a function. You could easily call an event handler just as you would call a function, except you would have to pass some event object to the event handler function, which is not always the case.
Basically you would never call an event handler as you would call a function, you would have something invoke the event when something is triggered, that may be the only difference.
I hope this post is helpful.
Well, event handlers are specific to the framework you use. Java's GUI model is based on even handlers, typically you pass an anonymous inner class that implements the expected interface (like KeyListener) to the addKeyListener (or similar) method.
In C, you typically use function pointers to the same effect. A button struct would hold a function pointer to a callback, and this function could be passed an event struct.
C++ allows you to use the function-pointer idea, or you can define an object that runs some method when you try to 'call' it - some_obj() on a suitably-defined object would call some function of your choice. You could even make it take arguments. Python is like this as well.
If a callback takes a parameter that specifies the event, it's typically called an event handler. But they can be used pretty much interchangeably.

What exactly is "application-defined" about UnhandledExceptionFilter?

MSDN describes UnhandledExceptionFilter as follows: "An application-defined function that passes unhandled exceptions to the debugger, if the process is being debugged."
But this function is clearly supplied by the OS, in kernel32.dll according to that same page.
So why do they call it an application-defined function?
Yes, very awkward language. It is a prototype definition of a function. Which you can use with the __except keyword or as an argument to SetUnhandledExceptionFilter(). Either would make yours an 'application defined function'.
There's default handling if you do neither, the debugger automatically stops at an unhandled exception. Which I suppose is what they meant with "that passes exceptions to the debugger". The SDK docs for SEH deserve an all-around failing grade.
UnhandledExceptionFilter() itself is not a function of its own provided by the kernel (although the kernel does implement its own default implementation that is used until you override it with your own). The UnhandledExceptionFilter() documentation you quote describes a function prototype that you have to follow if you choose to implement your own function and pass it to the SetUnhandledExceptionFilter() function to activate it within the kernel.

Resources