Semaphors with timeouts

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Semaphors with timeouts

Mülheims, Klaus
Hi,

I need a kind of Semaphore that waits only a predefined timeout, something like:
sem := Semaphore new.
gotSem := sem waitMaxTime: 45.

This methods returns true if a could enter the critical section. But if I'm blocked, I am only willing to wait for 45 seconds. If I cannot enter the critical section in this time, the method returns false and i can react on this timeout.

Has anybody seen such a behaviour in VisualWorks?

Greetings

Klasu Muelheims


Collogia AG
Ubierring 11
 
50678 Köln
Germany
+49 221 336080
http://www.collogia.de


Diese Nachricht ist vertraulich. Wenn Sie nicht der beabsichtigte Empfänger sind, informieren Sie bitte den Absender. Das unbefugte Kopieren oder Weiterleiten ist nicht gestattet. Wegen der Manipulierbarkeit von E-Mails übernehmen wir keine Haftung für den Inhalt.
Reply | Threaded
Open this post in threaded view
|

Re: Semaphors with timeouts

Reinout Heeck-2
Klaus,

I would fork of a process that after a delay signals the semaphore.

HTH,
Adriaan.


> Hi,
>
> I need a kind of Semaphore that waits only a predefined timeout, something
> like:
> sem := Semaphore new.
> gotSem := sem waitMaxTime: 45.
>
> This methods returns true if a could enter the critical section. But if
> I'm blocked, I am only willing to wait for 45 seconds. If I cannot enter
> the critical section in this time, the method returns false and i can
> react on this timeout.
>
> Has anybody seen such a behaviour in VisualWorks?
>
> Greetings
>
> Klasu Muelheims
>
>
> Collogia AG
> Ubierring 11
>
> 50678 Köln
> Germany
> +49 221 336080
> http://www.collogia.de
>
>
> Diese Nachricht ist vertraulich. Wenn Sie nicht der beabsichtigte
> Empfänger sind, informieren Sie bitte den Absender. Das unbefugte
> Kopieren oder Weiterleiten ist nicht gestattet. Wegen der
> Manipulierbarkeit von E-Mails übernehmen wir keine Haftung für den
> Inhalt.
>
>


--
http://vdg38bis.xs4all.nl


Reply | Threaded
Open this post in threaded view
|

Re: Semaphors with timeouts

Andre Schnoor
In reply to this post by Mülheims, Klaus
Check out the class Promise. That might be exactly what you are looking for.

Andre


Mülheims schrieb:

> Hi,
>
> I need a kind of Semaphore that waits only a predefined timeout, something like:
> sem := Semaphore new.
> gotSem := sem waitMaxTime: 45.
>
> This methods returns true if a could enter the critical section. But if I'm blocked, I am only willing to wait for 45 seconds. If I cannot enter the critical section in this time, the method returns false and i can react on this timeout.
>
> Has anybody seen such a behaviour in VisualWorks?
>
> Greetings
>
> Klasu Muelheims
>
>
> Collogia AG
> Ubierring 11
>  
> 50678 Köln
> Germany
> +49 221 336080
> http://www.collogia.de
>
>
> Diese Nachricht ist vertraulich. Wenn Sie nicht der beabsichtigte Empfänger sind, informieren Sie bitte den Absender. Das unbefugte Kopieren oder Weiterleiten ist nicht gestattet. Wegen der Manipulierbarkeit von E-Mails übernehmen wir keine Haftung für den Inhalt.
>  

Reply | Threaded
Open this post in threaded view
|

Re: Semaphors with timeouts

Reinout Heeck-2
In reply to this post by Mülheims, Klaus
Mülheims wrote:

> Hi,
>
> I need a kind of Semaphore that waits only a predefined timeout,
> something like: sem := Semaphore new. gotSem := sem waitMaxTime: 45.
>
> This methods returns true if a could enter the critical section. But
> if I'm blocked, I am only willing to wait for 45 seconds. If I cannot
> enter the critical section in this time, the method returns false and
> i can react on this timeout.
>
> Has anybody seen such a behaviour in VisualWorks?


Not exactly, but you can get inspiration from TimedPromise that lives in
the parcel Protocols-Common.

You might even be able to use TimedPromise directly if you don't mind
your critical section running in a forked thread...


R
-

Reply | Threaded
Open this post in threaded view
|

RE: Semaphors with timeouts

Terry Raymond
In reply to this post by Mülheims, Klaus
Llasu

Look at SocketAccessor>>handleAsyncConnect:timeout:.

You will see that it creates a delay and then grabs its
semaphore. The method then uses this semaphore as the one
to signal if the operation completes. Next it waits on
the delay.

Terry
 
===========================================================
Terry Raymond       Smalltalk Professional Debug Package
Crafted Smalltalk
80 Lazywood Ln.
Tiverton, RI  02878
(401) 624-4517      [hidden email]
<http://www.craftedsmalltalk.com>
===========================================================

> -----Original Message-----
> From: Mülheims, Klaus [mailto:[hidden email]]
> Sent: Monday, September 04, 2006 11:16 AM
> To: vwnc-list
> Subject: Semaphors with timeouts
>
> Hi,
>
> I need a kind of Semaphore that waits only a predefined timeout, something
> like:
> sem := Semaphore new.
> gotSem := sem waitMaxTime: 45.
>
> This methods returns true if a could enter the critical section. But if
> I'm blocked, I am only willing to wait for 45 seconds. If I cannot enter
> the critical section in this time, the method returns false and i can
> react on this timeout.
>
> Has anybody seen such a behaviour in VisualWorks?
>
> Greetings
>
> Klasu Muelheims
>
>
> Collogia AG
> Ubierring 11
>
> 50678 Köln
> Germany
> +49 221 336080
> http://www.collogia.de
>
>
> Diese Nachricht ist vertraulich. Wenn Sie nicht der beabsichtigte
> Empfänger sind, informieren Sie bitte den Absender. Das unbefugte Kopieren
> oder Weiterleiten ist nicht gestattet. Wegen der Manipulierbarkeit von E-
> Mails übernehmen wir keine Haftung für den Inhalt.

Reply | Threaded
Open this post in threaded view
|

Re: Semaphors with timeouts

arjen van elteren
In reply to this post by Mülheims, Klaus
> Hi,

Hi Klasu,

> I need a kind of Semaphore that waits only a predefined timeout,  
> something like:
> sem := Semaphore new.
> gotSem := sem waitMaxTime: 45.
>
> This methods returns true if a could enter the critical section. But if  
> I'm blocked, I am only willing to wait for 45 seconds. If I cannot enter  
> the critical section in this time, the method returns false and i can  
> react on this timeout.
>
> Has anybody seen such a behaviour in VisualWorks?

Yes, I've seen such behaviour in VisualWorks.

The Delay implementation is based on a semaphore that can be triggered.

delay := Delay forSeconds: 15
.
semaphore := delay delaySemaphore "use this semaphore to signal your  
process has finished"
.
delay wait
.
delay inProgress
        ifTrue: [
                "the semaphore was signalled before the delay was finished"
        ]
        ifFalse: [
                "the semaphore was not signalled on time"
        ]

Greetings,

Arjen van Elteren

> Greetings
>
> Klasu Muelheims
>
>
> Collogia AG
> Ubierring 11
> 50678 Köln
> Germany
> +49 221 336080
> http://www.collogia.de
>
>
> Diese Nachricht ist vertraulich. Wenn Sie nicht der beabsichtigte  
> Empfänger sind, informieren Sie bitte den Absender. Das unbefugte  
> Kopieren oder Weiterleiten ist nicht gestattet. Wegen der  
> Manipulierbarkeit von E-Mails übernehmen wir keine Haftung für den  
> Inhalt.



--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

Reply | Threaded
Open this post in threaded view
|

AW: Semaphors with timeouts

Mülheims, Klaus
In reply to this post by Mülheims, Klaus
Hi,

Thanks for the responses, due to my limited time for this "project" and the many different approaches to solve my problem, it will take some time to check out, what solution fits best for my problem.

Greetings

Klaus


Collogia AG
Ubierring 11
 
50678 Köln
Germany
+49 221 336080
http://www.collogia.de

-----Ursprüngliche Nachricht-----
Von: arjen van elteren [mailto:[hidden email]]
Gesendet: Montag, 4. September 2006 17:50
An: Mülheims, Klaus; vwnc-list
Betreff: Re: Semaphors with timeouts

> Hi,

Hi Klasu,

> I need a kind of Semaphore that waits only a predefined timeout,  
> something like:
> sem := Semaphore new.
> gotSem := sem waitMaxTime: 45.
>
> This methods returns true if a could enter the critical section. But if  
> I'm blocked, I am only willing to wait for 45 seconds. If I cannot enter  
> the critical section in this time, the method returns false and i can  
> react on this timeout.
>
> Has anybody seen such a behaviour in VisualWorks?

Yes, I've seen such behaviour in VisualWorks.

The Delay implementation is based on a semaphore that can be triggered.

delay := Delay forSeconds: 15
.
semaphore := delay delaySemaphore "use this semaphore to signal your  
process has finished"
.
delay wait
.
delay inProgress
        ifTrue: [
                "the semaphore was signalled before the delay was finished"
        ]
        ifFalse: [
                "the semaphore was not signalled on time"
        ]

Greetings,

Arjen van Elteren

> Greetings
>
> Klasu Muelheims
>
>
> Collogia AG
> Ubierring 11
> 50678 Köln
> Germany
> +49 221 336080
> http://www.collogia.de
>
>
> Diese Nachricht ist vertraulich. Wenn Sie nicht der beabsichtigte  
> Empfänger sind, informieren Sie bitte den Absender. Das unbefugte  
> Kopieren oder Weiterleiten ist nicht gestattet. Wegen der  
> Manipulierbarkeit von E-Mails übernehmen wir keine Haftung für den  
> Inhalt.



--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


Diese Nachricht ist vertraulich. Wenn Sie nicht der beabsichtigte Empfänger sind, informieren Sie bitte den Absender. Das unbefugte Kopieren oder Weiterleiten ist nicht gestattet. Wegen der Manipulierbarkeit von E-Mails übernehmen wir keine Haftung für den Inhalt.