Comments (7)
Iām sorry, can you clarify? Setting the event is completely independent (from the outside) from waiting on the event.
Example code that behaves differently on Linux and Windows would be helpful.
from pevents.
neosmart::while(WaitForEvent(event,-1))){
// now doing
do_something();
}
- when the
thread1
is executing do_something, it is not in a waiting state(NOT CALLING WaitForEvent), SetEvent should return an error.
neosmart::SetEvent(event);
-
linux: always return 0
Line 363 in 1209b1f
-
windows: an error will be returned when the notification fails
Line 603 in 1209b1f
from pevents.
@inaryart I tried to repo what you described for SetEvent. However, seems like I didn't see the error. SetEvent for the same event twice would just return 1
Here is my example code
https://github.com/yinsidij/pevents/blob/master/win32/HelloWorld.cpp
Here is the output running in windows (ret = 1 twice, which indicates success)
Thread 14076 waiting for write event...
Thread 18516 sets event...
ret = 1, error = 0
WaitForSingleObject returns 0
Thread 18516 sets event...
ret = 1, error = 0
The output is the same no matter the event is auto-reset or manual-reset or initialState signaled or nonsignaled.
Am I missing anything?
from pevents.
@inaryart I tried to repo what you described for SetEvent. However, seems like I didn't see the error. SetEvent for the same event twice would just return 1
Here is my example code
https://github.com/yinsidij/pevents/blob/master/win32/HelloWorld.cppHere is the output running in windows (ret = 1 twice, which indicates success)
Thread 14076 waiting for write event...
Thread 18516 sets event...
ret = 1, error = 0
WaitForSingleObject returns 0
Thread 18516 sets event...
ret = 1, error = 0The output is the same no matter the event is auto-reset or manual-reset or initialState signaled or nonsignaled.
Am I missing anything?
you are right, setEvent
will be return 1
, so i think linux should also return the same value(1
), so that I can judge whether the wake-up(setevent
) operation failed
from pevents.
I think neosmart::event uses return value of 0 as success, which is oppose to windows convention (return value of 1 as success). So you might want to update up-level checker.
from pevents.
I think this is normal code, it should be part of the project.
if(setevent(event) == 1){
// then i known
failedCount++;
}
just as my suggestion...
from pevents.
I think you are misunderstanding what an error in this context means. The calls are fully asynchronous, and will succeed regardless of whether there is another thread on the other end - a SetEvent()
on an already set event will succeed, and it doesn't rendezvous with the thread calling WaitForSingleEvent()
before it returns. An error is only something out of the ordinary caused by either an internal bug in the pthreads interfacing or the user providing an invalid argument (e.g. making up a value for the event
parameter and passing it in).
The convention on Linux and with the pthreads library (which this library serves as some sort of extension to) is for functions to return error numbers with a return value of zero being no error. Don't check for if (SetEvent(...) == 1)
but rather if (SetEvent(...) != 0)
because there are no guarantees made that one is (always or the only) error returned.
from pevents.
Related Issues (11)
- can we destroy pthread_mutex objects in locked state? HOT 1
- WaitForMultipleThreads HOT 1
- WaitForEvent( 0 ) can return WAIT_TIMEOUT under lock contention when actually in the signaled state HOT 4
- Lost Wake-Up Problem HOT 7
- Create a tag release 1.0 HOT 1
- RFC: Change WFMO ifdef to NO_WFMO
- Use an intrusive list to track WFMO waiters
- WaitForMultipleEvents incorrectly returns WAIT_TIMEOUT when all events already signaled, WaitAll is True, and Timeout is 0 HOT 1
- pthread_mutex_lock deadlock in ResetEvent() and WaitForEvent() under Android when abi is arm64-v8a HOT 2
- WFME( waitAll = true ) resets AutoReset Events before all Events are set HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
š Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ššš
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ā¤ļø Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pevents.