Multiple libevent bases in different threads on the same fd - pthreads

I'm curious to know if anyone else has tried this... I'm about to give it a go, but was hoping someone else may have some experience to share before I sit here at 11:00 pm (having to go to work in the morning) to try this.
If I load up a few threads, and from each thread create an event base and create listen events on the same fd, how would libevent respond to that? Would only one of the event bases end up winning and triggering an event, or would each one end up triggering the event?

Well, I went ahead and coded it up real quick. Unfortunately, as I suspected, every single event base fires off an event. So with four threads, each with their own unique event base and set of events on the same fd, it triggered the function four times.

Related

Event Consolidation when there is no defined time window for Event Arrival

We have a single topic called migrationstatus, assume we partition so that all instances and events for a given MigrationCandidateNumber always end up on the same topic and partition.
Following event arrives at 12-10-2019 at 10:00 AM
{
"MigrationCandidateNumber": 54545451,
"MigrationStatus":"Final Bill Produced"
}
Following event arrives at 14-10-2019 at 08:00 AM
{
"MigrationCandidateNumber": 54545451,
"MigrationStatus":"Product Ready"
}
Following event arrives at 17-10-2019 at 12:00 AM
{
"MigrationCandidateNumber": 54545451,
"MigrationStatus":"Registration Complete"
}
Problem Statement:
Once all 3 of those events have been processed, we need to produce the event below onto migrationstatus-out topic as shown below:
{
"MigrationCandidateNumber": **54545451**,
"MigrationStatus":"**Ready for extract 2**"
}
The wide time window is deliberate, since the first 3 events could arrive days apart.
Best way of doing this with no external database?
Solution Tried:
You can't use windowed aggregation because we are not sure about when event arrives.
created 3 streams out of the main stream for different migration status but again stream-stream joins are windowed.
For this scenario I don't see a way to aggregate data so that we store data in KSQL table and perform a group by to check If messages with all the status has arrived.
I know its a wide open question and mostly related to approach for solving the problem rather than technical issue but I couldn't find a better forum to post this.
I have solved this problem and shared the code in github. Please follow the link for the solution.
GitHub link for the solution
Thanks MatthiasJ.Sax for the heads up.

XGrabPointer poll till next event or pipe

I was trying to write a mouse event listener. This was my approach, can you please tell me if this will work before I start writing it. I'm writing it in ctypes, so if I ctype it all (couple days) then find out it doesnt work its a loss of time.
My goal is, that I should be able to cancel the poll via a pipe. This was my approach:
In another thread call XThreadsInit
Open XDisplay display
XGrabPointer to display
get file descriptor ConnectionNumber(display)
connect to pipe that was made on main thread
Do a pselect with no timeout timeout is set to null on pipe and fd from 4
Is this right approach?
Thanks
If you are using threads you are sharing variables between threads. It would be much simpler to use a global variable that is set when the poll must be aborted, then in your watch thread create a tight loop that checks for that variable and use a short timeout in pselect(). This may introduce a short delay but if you keep the timeout short (say, 100 ms) it would be hardly noticable and still efficient.

EKAlarms with relativeOffset

I'm currently trying to write a method to compare EKAlarms to one another. The problem with this is between absoluteDate and relativeOffset. Comparing two alarms each with an absoluteDate is easy, but if one or both have a relativeOffset, you need to know what event they're relatively offset from. As per the documentation,
relativeOffset: The offset from the start of an event, at which the alarm fires.
Yet, I see no documentation on setting the trigger for a relativeOffset alarm. Can anyone help me figure out what I'm missing? How can I compare two EKAlarms with relativeOffsets?
Thanks for the help!
As you rightly say:
if one or both have a relativeOffset, you need to know what event they're relatively offset from
Quite so. But how can you possibly not know that? EKAlarms do not float around loose, falling from the sky like snowflakes. If not attached to an EKCalendarItem, a relative EKAlarm is meaningless; there is nothing to compare. If it is attached to an EKCalendarItem, then you clearly know that fact - otherwise, where would you have gotten the alarm from??? Either you just created the alarm, and are about to attach it to an EKCalendarItem yourself, or you have started with the EKCalendarItem and have looked at its alarms property, in which case you also know the EKCalendarItem's startDate and can calculate from there.

How do you make a combo of two emotes in lua in World of Warcraft work?

How do you make a combo of two emotes in lua in World of Warcraft work?
function Button2_OnClick()
PlaySoundFile("Interface\\Addons\\Fart\\common_fart[1].wav");
DoEmote("moon");
DoEmote("sit");
DoEmote("dance");
DoEmote("beckon");
end
I am using Wow Addon Studio to make a fart application on Wow.
I used this function, and only the sit motion showed, and beckon and moon only showed on the chat window. The dance emote didn't show up anywhere.
Blizzard has explicitly prohibited anything that can be used to make lua wait or pause because it is an essential ingredient to making a gold mining or grinding bot.
There isn't a native (i.e. lua only) way to have lua wait without using all the CPU. Outside of the WOW client, you'd use win.sleep or some other 3rd party API call that calls into the host application or operating systems threading functions.
It may be possible to simulate a wait by having code execute on a frequent event (such as text arriving at the chat window) and then in the event handler checking to see if enough time has passed to permit executing the next command in the sequence. This probably wouldn't be a very accurate timer and it would be rather complex as you'd have to create a data structure to hold the sequence of commands, the timings between each, the current command, etc. and so on.
This may be an intentional limitation of the API to prevent in game automation (botting).
What has worked for me is to have a global variable that is incremented through the loop. Such as
Integer count = 0;
function Button2_OnClick()
i++
switch
case(1)
PlaySoundFile("Interface\\Addons\\Fart\\common_fart[1].wav");
case(2)
DoEmote("moon");
case(3)
DoEmote("sit");
case(4)
DoEmote("dance");
case(5)
DoEmote("beckon");
default
i=0;
end
end
What you would have to do then is to click the button multiple times, but you would get the effect you're going for.
I would suggest you wait some time before doing the next emote. As far as I know, the server disconnects you if you spam too much. This might just trigger it sometimes.
Besides that, I guess maybe the client has a way of preventing it? In either case, I would suggest you add some sort of fraction-of-a-second delay between the emotes.
Cheers,
Amit Ron
Could it be that the last two can't be done while sitting?
infact, integer i = 0, because defining integer 'count' and then using i is incorrect. :)

RxSwift: Receive events immediately, unless the last event was processed within a certain interval

New to RxSwift / Reactivex. Basically what I'm trying to do is to make a server call whenever something happens, but make sure it's not done more often than every 10 seconds. Less often if possible.
For instance, whenever an event ("needs update") is generated I'd like to call the server immediately if more than 10 seconds have passed since my last call. If less time has passed I'd like to make the call on the 10 second mark from the last one. It doesn't matter how many events have been generated within these 10 seconds.
I looked at the description of throttle but it appears to starve if events happen very quickly, which isn't desirable.
How can I achieve this?
There's a proposed new operator for RxSwiftExt that would give you something you're looking for, I think. However, it doesn't exist yet. You might want to keep an eye on it, though.
https://github.com/RxSwiftCommunity/RxSwiftExt/issues/10

Resources