Here is a simple event semaphore class, in a separate file for ::requires.
::class 'EventSemaphore' public::method init
expose posted
posted = .false
::method post
expose posted
posted = .true
::method wait
expose posted
if posted then do
posted = .false
return
end
guard on when posted
posted = .false
Here is a simple file demonstrating the usage:
sem = .EventSemaphore~new
runner = .Runner~new(sem)
loop 5
delay = random(1,5)
say "Waiting for" delay "seconds"
call syssleep delay
say "Posting event"
sem~postend
say "Terminating"
runner~quit = .true
sem~post
::class runner::method init
expose quit
use strict arg sem
quit = .false
reply
loop while \quit
say "Waiting for an event"
sem~wait
say "Event received"
end
::attribute quit set unguarded
::requires "EventSemaphore.cls"
On Fri, Jan 9, 2015 at 8:09 AM, Rick McGuire <object.r...@gmail.com> wrote:
> Yes, but you can create methods on the class that allow the other thread
> to set the variable. Or you can use a object instance that both threads
> have access to as an intermediary.
>
> Rick
>
> On Fri, Jan 9, 2015 at 8:06 AM, Staffan Tylen <staffan.ty...@gmail.com>
> wrote:
>
>> OK thanks. Just to clarify, The waiting method needs to wait for an event
>> in a method located in a different class! Reading about the GUARD
>> instruction it makes me believe that it only works within the same class
>> because of the EXPOSE instruction requirement. But I may be wrong ...
>>
>> Staffan
>>
>>
>> On Fri, Jan 9, 2015 at 1:46 PM, Rick McGuire <object.r...@gmail.com>
>> wrote:
>>
>>> If you are doing everything in a single process, you can use the guard
>>> instruction to wait for a variable to get set. I don't have time right
>>> now, but I'll see if I can't whip up a simple semaphore class for you in a
>>> little bit.
>>>
>>> Rick
>>>
>>> On Fri, Jan 9, 2015 at 7:36 AM, Staffan Tylen <staffan.ty...@gmail.com>
>>> wrote:
>>>
>>>> Thanks Rick. Yes, it seems to work when I use the handle from
>>>> SysOpenEventSem as argument to other functions.
>>>>
>>>> I'm trying to use this technique to wait for an event in a second
>>>> thread but are there better or other ways to do that?
>>>>
>>>> Staffan
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> ------------------------------------------------------------------------------
>>>> Dive into the World of Parallel Programming! The Go Parallel Website,
>>>> sponsored by Intel and developed in partnership with Slashdot Media, is
>>>> your
>>>> hub for all things parallel software development, from weekly thought
>>>> leadership blogs to news, videos, case studies, tutorials and more.
>>>> Take a
>>>> look and join the conversation now. http://goparallel.sourceforge.net
>>>> _______________________________________________
>>>> Oorexx-users mailing list
>>>> Oorexx-users@lists.sourceforge.net
>>>> https://lists.sourceforge.net/lists/listinfo/oorexx-users
>>>>
>>>>
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> Dive into the World of Parallel Programming! The Go Parallel Website,
>>> sponsored by Intel and developed in partnership with Slashdot Media, is
>>> your
>>> hub for all things parallel software development, from weekly thought
>>> leadership blogs to news, videos, case studies, tutorials and more. Take
>>> a
>>> look and join the conversation now. http://goparallel.sourceforge.net
>>> _______________________________________________
>>> Oorexx-users mailing list
>>> Oorexx-users@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/oorexx-users
>>>
>>>
>>
>>
>> ------------------------------------------------------------------------------
>> Dive into the World of Parallel Programming! The Go Parallel Website,
>> sponsored by Intel and developed in partnership with Slashdot Media, is
>> your
>> hub for all things parallel software development, from weekly thought
>> leadership blogs to news, videos, case studies, tutorials and more. Take a
>> look and join the conversation now. http://goparallel.sourceforge.net
>> _______________________________________________
>> Oorexx-users mailing list
>> Oorexx-users@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/oorexx-users
>>
>>
>
------------------------------------------------------------------------------
Dive into the World of Parallel Programming! The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net
_______________________________________________
Oorexx-users mailing list
Oorexx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-users