Giter VIP home page Giter VIP logo

Comments (7)

mqudsi avatar mqudsi commented on August 22, 2024

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.

romanholidaypancakes avatar romanholidaypancakes commented on August 22, 2024
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);

from pevents.

yinsidij avatar yinsidij commented on August 22, 2024

@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.

romanholidaypancakes avatar romanholidaypancakes commented on August 22, 2024

@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?

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.

yinsidij avatar yinsidij commented on August 22, 2024

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.

romanholidaypancakes avatar romanholidaypancakes commented on August 22, 2024

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.

mqudsi avatar mqudsi commented on August 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    šŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ā¤ļø Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.