Revision history for KeyPgCondSignal


Revision [26794]

Last edited on 2024-03-13 10:37:35 by fxm [added link to 'CondBroadcast']
Additions:
See also ##[[KeyPgCondCreate|Condcreate]]## and ##[[KeyPgCondWait|Condwait]]## and ##[[KeyPgCondBroadcast|Condbroadcast]]##
Deletions:
See also ##[[KeyPgCondCreate|Condcreate]]## and ##[[KeyPgCondWait|Condwait]]##


Revision [24756]

Edited on 2020-11-30 03:46:26 by fxm [renaming 'main thread' to 'implicit main thread']
Additions:
Once the conditional is created with ##[[KeyPgCondCreate|Condcreate]]## and the threads are started, one of more of them (including the implicit main thread executing main program) can be set to ##[[KeyPgCondWait|Condwait]]## for the conditional, they will be stopped until some other thread ##[[KeyPgCondSignal|Condsignal]]##s that the waiting thread can restart. ##[[KeyPgCondBroadcast|Condbroadcast]]## can be used to restart all threads waiting for the conditional. At the end of the program ##[[KeyPgCondDestroy|Conddestroy]]## must be used to avoid leaking resources in the OS.
Deletions:
Once the conditional is created with ##[[KeyPgCondCreate|Condcreate]]## and the threads are started, one of more of them (including the main thread executing main program) can be set to ##[[KeyPgCondWait|Condwait]]## for the conditional, they will be stopped until some other thread ##[[KeyPgCondSignal|Condsignal]]##s that the waiting thread can restart. ##[[KeyPgCondBroadcast|Condbroadcast]]## can be used to restart all threads waiting for the conditional. At the end of the program ##[[KeyPgCondDestroy|Conddestroy]]## must be used to avoid leaking resources in the OS.


Revision [24559]

Edited on 2020-10-01 02:04:08 by fxm [replaced 'Sleep x' with 'Sleep x, 1' in critical sections]
Additions:
Sleep 400, 1
Deletions:
Sleep 400


Revision [23726]

Edited on 2019-10-20 02:43:39 by RoBert [Changed an instance of the word "routine" to "subroutine"]
Additions:
**Condsignal** restarts one thread waiting. It should be called after ##//mutex//## is locked (using the same ##//mutex//## as one used with ##[[KeyPgCondWait|Condwait]]##). If no threads are waiting on the conditional, nothing happens (the signal is lost forever); if several are waiting, only one is restarted. The caller must then unlock ##//mutex//## in order for ##[[KeyPgCondWait|Condwait]]## subroutine to complete.
Deletions:
**Condsignal** restarts one thread waiting. It should be called after ##//mutex//## is locked (using the same ##//mutex//## as one used with ##[[KeyPgCondWait|Condwait]]##). If no threads are waiting on the conditional, nothing happens (the signal is lost forever); if several are waiting, only one is restarted. The caller must then unlock ##//mutex//## in order for ##[[KeyPgCondWait|Condwait]]## routine to complete.


Revision [23321]

Edited on 2019-09-09 14:37:04 by fxm [typo]
Additions:
The handle of a conditional variable.
Deletions:
The handle of a conditional variable, or the null pointer (0) on failure.


Revision [21490]

Edited on 2016-05-19 08:00:19 by fxm [Updated the comment of example]
Additions:
' Thread_signal = true -------------------> While Thread_signal <> true
Deletions:
' Thread_signal = true While Thread_signal <> true


Revision [21488]

Edited on 2016-05-19 07:40:13 by fxm [Updated the comment of example]
Additions:
' Thread#A XOR + ==> Thread#B
'..... .....
'MutexLock(mut) MutexLock(mut)
' Do_something_with_exclusion Do_something_with_exclusion
' Thread_signal = true While Thread_signal <> true
' CondSignal(cond) -------------------------> CondWait(cond, mut)
' Do_something_with_exclusion .------> Wend
'MutexUnlock(mut) ------------------' Thread_signal = false
'..... Do_something_with_exclusion
'..... MutexUnlock(mut)
'..... .....
Deletions:
' Thread#A XOR + ==> Thread#B
'..... .....
'MutexLock(mut) MutexLock(mut)
' Do_something_with_exclusion While Thread_signal <> true
' Thread_signal = true .-------------> CondWait(cond, mut)
' CondSignal(cond) ---------------' .------> Wend
'MutexUnlock(mut) ----------------------' Do_something_with_exclusion
'..... Thread_signal = false
'..... MutexUnlock(mut)
'..... .....


Revision [21486]

Edited on 2016-05-19 06:34:43 by fxm [[Updated the comment of example]
Additions:
'MutexLock(mut) MutexLock(mut)
' Do_something_with_exclusion While Thread_signal <> true
' Thread_signal = true .-------------> CondWait(cond, mut)
' CondSignal(cond) ---------------' .------> Wend
'MutexUnlock(mut) ----------------------' Do_something_with_exclusion
'..... Thread_signal = false
Deletions:
'MutexLock(mut) .....
' Do_something#A_with_exclusion MutexLock(mut)
' Thread#A_signal = true While Thread#A_signal <> true
' CondSignal(cond) -----------------------------> CondWait(cond, mut)
'MutexUnlock(mut) -----------------------------> Wend
'..... Do_something#B_with_exclusion
'..... Thread#A_signal = false


Revision [21484]

Edited on 2016-05-19 04:22:42 by fxm [Updated the comment of example]
Additions:
'MutexLock(mut) .....
' Do_something#A_with_exclusion MutexLock(mut)
' Thread#A_signal = true While Thread#A_signal <> true
' CondSignal(cond) -----------------------------> CondWait(cond, mut)
'MutexUnlock(mut) -----------------------------> Wend
'..... Do_something#B_with_exclusion
'..... MutexUnlock(mut)
Deletions:
'MutexLock(mut) MutexLock(mut)
' Do_something#A_with_exclusion While Thread#A_signal <> true
' Thread#A_signal = true CondWait(cond, mut)
' CondSignal(cond) Wend
'MutexUnlock(mut) Do_something#B_with_exclusion
' MutexUnlock(mut)
' .....


Revision [21479]

Edited on 2016-05-17 17:00:55 by fxm [Added precision]
Additions:
**Condsignal** restarts one thread waiting. It should be called after ##//mutex//## is locked (using the same ##//mutex//## as one used with ##[[KeyPgCondWait|Condwait]]##). If no threads are waiting on the conditional, nothing happens (the signal is lost forever); if several are waiting, only one is restarted. The caller must then unlock ##//mutex//## in order for ##[[KeyPgCondWait|Condwait]]## routine to complete.
Deletions:
**Condsignal** restarts one thread waiting. It should be called after ##//mutex//## is locked (using the same ##//mutex//## as one used with ##[[KeyPgCondWait|Condwait]]##). If no threads are waiting on the conditional, nothing happens; if several are waiting, only one is restarted. The caller must then unlock ##//mutex//## in order for ##[[KeyPgCondWait|Condwait]]## routine to complete.


Revision [20854]

Edited on 2016-03-12 15:54:06 by fxm [Formatting]
Additions:


Revision [20098]

Edited on 2016-02-10 15:55:53 by DkLwikki [Update link format]
Additions:
Restarts a thread suspended by a call to ##[[KeyPgCondWait|Condwait]]##
[[KeyPgDeclare|declare]] [[KeyPgSub|sub]] **Condsignal** ( [[KeyPgByval|byval]] //handle// [[KeyPgAs|as]] [[KeyPgAny|any]] [[KeyPgPtr|ptr]] )
Once the conditional is created with ##[[KeyPgCondCreate|Condcreate]]## and the threads are started, one of more of them (including the main thread executing main program) can be set to ##[[KeyPgCondWait|Condwait]]## for the conditional, they will be stopped until some other thread ##[[KeyPgCondSignal|Condsignal]]##s that the waiting thread can restart. ##[[KeyPgCondBroadcast|Condbroadcast]]## can be used to restart all threads waiting for the conditional. At the end of the program ##[[KeyPgCondDestroy|Conddestroy]]## must be used to avoid leaking resources in the OS.
**Condsignal** restarts one thread waiting. It should be called after ##//mutex//## is locked (using the same ##//mutex//## as one used with ##[[KeyPgCondWait|Condwait]]##). If no threads are waiting on the conditional, nothing happens; if several are waiting, only one is restarted. The caller must then unlock ##//mutex//## in order for ##[[KeyPgCondWait|Condwait]]## routine to complete.
See also ##[[KeyPgCondCreate|Condcreate]]## and ##[[KeyPgCondWait|Condwait]]##
- Threading is not allowed in //[[CompilerOptlang|-lang qb]]//
- ##[[KeyPgCondCreate|Condcreate]]##
- ##[[KeyPgCondDestroy|Conddestroy]]##
- ##[[KeyPgCondBroadcast|Condbroadcast]]##
- ##[[KeyPgCondWait|Condwait]]##
- ##[[KeyPgThreadCreate|Threadcreate]]##
Deletions:
Restarts a thread suspended by a call to ##[[KeyPgCondWait Condwait]]##
[[KeyPgDeclare declare]] [[KeyPgSub sub]] **Condsignal** ( [[KeyPgByval byval]] //handle// [[KeyPgAs as]] [[KeyPgAny any]] [[KeyPgPtr ptr]] )
Once the conditional is created with ##[[KeyPgCondCreate Condcreate]]## and the threads are started, one of more of them (including the main thread executing main program) can be set to ##[[KeyPgCondWait Condwait]]## for the conditional, they will be stopped until some other thread ##[[KeyPgCondSignal Condsignal]]##s that the waiting thread can restart. ##[[KeyPgCondBroadcast Condbroadcast]]## can be used to restart all threads waiting for the conditional. At the end of the program ##[[KeyPgCondDestroy Conddestroy]]## must be used to avoid leaking resources in the OS.
**Condsignal** restarts one thread waiting. It should be called after ##//mutex//## is locked (using the same ##//mutex//## as one used with ##[[KeyPgCondWait Condwait]]##). If no threads are waiting on the conditional, nothing happens; if several are waiting, only one is restarted. The caller must then unlock ##//mutex//## in order for ##[[KeyPgCondWait Condwait]]## routine to complete.
See also ##[[KeyPgCondCreate Condcreate]]## and ##[[KeyPgCondWait Condwait]]##
- Threading is not allowed in //[[CompilerOptlang -lang qb]]//
- ##[[KeyPgCondCreate Condcreate]]##
- ##[[KeyPgCondDestroy Conddestroy]]##
- ##[[KeyPgCondBroadcast Condbroadcast]]##
- ##[[KeyPgCondWait Condwait]]##
- ##[[KeyPgThreadCreate Threadcreate]]##


Revision [17849]

Edited on 2015-12-06 05:43:34 by FxMwikki [swapped two comment lines for better understanding]
Additions:
' The main routine waits until receive the condition signal from the thread, then print the complemented string.
' The thread complements the string, then sends a condition signal.
'Principle of mutual exclusion + simple synchronization
Deletions:
' The thread complementes the string, then sends a condition signal.
' The main routine waits until receive the condition signal, then print the complemented string.
'Principle of mutual exclusion + simple synchronisation


Revision [17645]

Edited on 2015-05-01 07:03:48 by FxMwikki [Update example]
Additions:
'
'Principle of mutual exclusion + simple synchronisation
' Thread#A XOR + ==> Thread#B
'..... .....
'MutexLock(mut) MutexLock(mut)
' Do_something#A_with_exclusion While Thread#A_signal <> true
' Thread#A_signal = true CondWait(cond, mut)
' CondSignal(cond) Wend
'MutexUnlock(mut) Do_something#B_with_exclusion
'..... Thread#A_signal = false
' MutexUnlock(mut)
' .....
While ok <> 1
ok = 0
Deletions:
While ok = 0


Revision [17638]

Edited on 2015-04-28 08:04:56 by FxMwikki [Added clarification]
Additions:
**Condsignal** restarts one thread waiting. It should be called after ##//mutex//## is locked (using the same ##//mutex//## as one used with ##[[KeyPgCondWait Condwait]]##). If no threads are waiting on the conditional, nothing happens; if several are waiting, only one is restarted. The caller must then unlock ##//mutex//## in order for ##[[KeyPgCondWait Condwait]]## routine to complete.
Deletions:
**Condsignal** restarts one thread waiting. It should be called after ##//mutex//## is locked (using the same mutex as one used with ##[[KeyPgCondWait Condwait]]##). If no threads are waiting on the conditional, nothing happens; if several are waiting, only one is restarted. The caller must then unlock ##//mutex//## in order for ##[[KeyPgCondWait Condwait]]## routine to complete.


Revision [17636]

Edited on 2015-04-28 07:52:02 by FxMwikki [Added clarification]
Additions:
**Condsignal** restarts one thread waiting. It should be called after ##//mutex//## is locked (using the same mutex as one used with ##[[KeyPgCondWait Condwait]]##). If no threads are waiting on the conditional, nothing happens; if several are waiting, only one is restarted. The caller must then unlock ##//mutex//## in order for ##[[KeyPgCondWait Condwait]]## routine to complete.
Deletions:
**Condsignal** restarts one thread waiting. It should be called after ##//mutex//## is locked. If no threads are waiting on the conditional, nothing happens; if several are waiting, only one is restarted. The caller must then unlock ##//mutex//## in order for ##[[KeyPgCondWait Condwait]]## routine to complete.


Revision [17629]

Edited on 2015-04-27 05:32:22 by FxMwikki [Improved example with protected CondWait against suprious wakeups]
Additions:
Dim Shared As Integer ok = 0
Sub thread (ByVal p As Any Ptr)
MutexLock(mutex)
ok = 1
CondSignal(cond)
MutexUnlock(mutex)
mutex = MutexCreate
cond = CondCreate
MutexLock(mutex)
pt = ThreadCreate(@thread)
While ok = 0
CondWait(cond, mutex)
Wend
MutexUnlock(mutex)
ThreadWait(pt)
MutexDestroy(mutex)
CondDestroy(cond)
Deletions:
Sub thread (Byval p As Any Ptr)
Mutexlock(mutex)
Condsignal(cond)
Mutexunlock(mutex)
mutex = Mutexcreate
cond = Condcreate
Mutexlock(mutex)
pt = Threadcreate(@thread)
Condwait(cond, mutex)
Mutexunlock(mutex)
Threadwait(pt)
Mutexdestroy(mutex)
Conddestroy(cond)


Revision [17628]

Edited on 2015-04-27 02:16:07 by FxMwikki [Added a delay before CondSignal for demonstrate the operation of CondWait]
Additions:
Sleep 400


Revision [17624]

Edited on 2015-04-26 16:13:09 by FxMwikki [Added example]
Additions:
See also ##[[KeyPgCondCreate Condcreate]]## and ##[[KeyPgCondWait Condwait]]##
{{fbdoc item="filename" value="examples/manual/threads/condsignal.bas"}}%%(freebasic)
' This very simple example code demonstrates the use of several condition variable routines.
' The main routine initializes a string and creates one thread.
' The thread complementes the string, then sends a condition signal.
' The main routine waits until receive the condition signal, then print the complemented string.
Dim Shared As Any Ptr mutex
Dim Shared As Any Ptr cond
Dim Shared As String txt
Dim As Any Ptr pt
Sub thread (Byval p As Any Ptr)
Print "thread is complementing the string"
txt &= " complemented by thread"
Print "thread signals the processing completed"
Mutexlock(mutex)
Condsignal(cond)
Mutexunlock(mutex)
End Sub
mutex = Mutexcreate
cond = Condcreate
txt = "example of text"
Print "main() initializes a string = " & txt
Print "main creates one thread"
Print
Mutexlock(mutex)
pt = Threadcreate(@thread)
Condwait(cond, mutex)
Mutexunlock(mutex)
Print
Print "back in main(), the string = " & txt
Threadwait(pt)
Mutexdestroy(mutex)
Conddestroy(cond)
%%
Deletions:
See ##[[KeyPgCondCreate Condcreate]]## and ##[[KeyPgCondWait Condwait]]##


Revision [17622]

Edited on 2015-04-26 07:01:41 by FxMwikki [Added link to other example]
Additions:
See ##[[KeyPgCondCreate Condcreate]]## and ##[[KeyPgCondWait Condwait]]##
Deletions:
See ##[[KeyPgCondCreate Condcreate]]##


Revision [17618]

Edited on 2015-04-26 02:22:09 by FxMwikki [Added explanation]
Additions:
**Condsignal** restarts one thread waiting. It should be called after ##//mutex//## is locked. If no threads are waiting on the conditional, nothing happens; if several are waiting, only one is restarted. The caller must then unlock ##//mutex//## in order for ##[[KeyPgCondWait Condwait]]## routine to complete.
Deletions:
**Condsignal** restarts one thread waiting; if no threads are waiting on the conditional, nothing happens; if several are waiting, only one is restarted.


Revision [17615]

Edited on 2015-04-25 16:24:49 by FxMwikki [Added explanation]
Additions:
**Condsignal** restarts one thread waiting; if no threads are waiting on the conditional, nothing happens; if several are waiting, only one is restarted.
Deletions:
**Condsignal** restarts one thread waiting. If no threads are waiting on the conditional, nothing happens. If several are waiting, only one is restarted.


Revision [17612]

Edited on 2015-04-25 16:14:40 by FxMwikki [Added explaination]
Additions:
Once the conditional is created with ##[[KeyPgCondCreate Condcreate]]## and the threads are started, one of more of them (including the main thread executing main program) can be set to ##[[KeyPgCondWait Condwait]]## for the conditional, they will be stopped until some other thread ##[[KeyPgCondSignal Condsignal]]##s that the waiting thread can restart. ##[[KeyPgCondBroadcast Condbroadcast]]## can be used to restart all threads waiting for the conditional. At the end of the program ##[[KeyPgCondDestroy Conddestroy]]## must be used to avoid leaking resources in the OS.
**Condsignal** restarts one thread waiting. If no threads are waiting on the conditional, nothing happens. If several are waiting, only one is restarted.
Deletions:
Once the conditional is created with ##[[KeyPgCondCreate Condcreate]]## and the threads are started, one of more of them can be set to ##[[KeyPgCondWait Condwait]]## for the conditional, they will be stopped until some other thread ##[[KeyPgCondSignal Condsignal]]##s that the waiting thread can restart. ##[[KeyPgCondBroadcast Condbroadcast]]## can be used to restart all threads waiting for the conditional. At the end of the program ##[[KeyPgCondDestroy Conddestroy]]## must be used to avoid leaking resources in the OS.


Revision [14277]

Edited on 2009-08-29 21:51:50 by CountingPine [Remove CamelCase links in "New to FreeBASIC"]
Additions:
- New to ""FreeBASIC""
Deletions:
- New to FreeBASIC


Revision [14013]

Edited on 2008-12-13 12:46:12 by LaananFisher [Updated: minor formatting]
Additions:
[[KeyPgDeclare declare]] [[KeyPgSub sub]] **Condsignal** ( [[KeyPgByval byval]] //handle// [[KeyPgAs as]] [[KeyPgAny any]] [[KeyPgPtr ptr]] )
Deletions:
[[KeyPgDeclare declare]] [[KeyPgSub sub]] **Condsignal** ( [[KeyPgByval byval]] //handle// [[KeyPgAs as]] [[KeyPgAny any]] [[KeyPgPtr ptr]])


Revision [12244]

The oldest known version of this page was created on 2008-01-18 14:08:50 by JeffMarshall [Updated: minor formatting]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode