I have a short semaphore app that I used a month ago or so to test semaphore's and it ran fine. I just ran it again and it does not run properly. The app code:
import groovy.transform.Field
@Field static Number RunNumber = 1
definition(
name: "SemaphoreTest1",
namespace: "Example",
author: "Hubitat Example",
description: "Test Semaphors",
category: "Convenience",
iconUrl: "",
iconX2Url: "",
singleThreaded: false)
def installed() {
log.debug "installed()"
updated()
}
def updated() {
log.debug "updated(" + RunNumber + ")"
RunNumber++
trace()
}
def uninstalled() {
log.debug "uninstalled()"
}
def trace()
{
[0,1,2,3].each { runInMillis(0, "MySemaphore", [overwrite: false, data: "Test${it}"]) }
}
def MySemaphore(String Line) {
log.debug "BEFORE synchronized()"
synchronized(this.MySemaphore) {
log.debug "*** ENTER MYSEMAPHORE ***"
log.debug Line
pauseExecution(1000) // pause for a second
log.debug "*** EXIT MYSEMAPHORE ***"
}
}
I then installed it and hit Done and then went back in to the app and hit Done again:
app:10492024-03-20 07:08:23.180 PMdebug*** EXIT MYSEMAPHORE ***
app:10492024-03-20 07:08:22.182 PMdebugTest1
app:10492024-03-20 07:08:22.179 PMdebug*** ENTER MYSEMAPHORE ***
app:10492024-03-20 07:08:22.177 PMdebug*** EXIT MYSEMAPHORE ***
app:10492024-03-20 07:08:21.179 PMdebugTest2
app:10492024-03-20 07:08:21.176 PMdebug*** ENTER MYSEMAPHORE ***
app:10492024-03-20 07:08:21.173 PMdebug*** EXIT MYSEMAPHORE ***
app:10492024-03-20 07:08:20.175 PMdebugTest3
app:10492024-03-20 07:08:20.173 PMdebug*** ENTER MYSEMAPHORE ***
app:10492024-03-20 07:08:20.170 PMdebug*** EXIT MYSEMAPHORE ***
app:10492024-03-20 07:08:19.373 PMdebugBEFORE synchronized()
app:10492024-03-20 07:08:19.275 PMdebugBEFORE synchronized()
app:10492024-03-20 07:08:19.220 PMdebugBEFORE synchronized()
app:10492024-03-20 07:08:19.172 PMdebugTest0
app:10492024-03-20 07:08:19.169 PMdebug*** ENTER MYSEMAPHORE ***
app:10492024-03-20 07:08:19.166 PMdebugBEFORE synchronized()
app:10492024-03-20 07:08:19.069 PMdebugupdated(2)
app:10492024-03-20 07:08:12.611 PMdebug*** EXIT MYSEMAPHORE ***
app:10492024-03-20 07:08:11.613 PMdebugTest2
app:10492024-03-20 07:08:11.610 PMdebug*** ENTER MYSEMAPHORE ***
app:10492024-03-20 07:08:11.607 PMdebug*** EXIT MYSEMAPHORE ***
app:10492024-03-20 07:08:10.610 PMdebugTest3
app:10492024-03-20 07:08:10.606 PMdebug*** ENTER MYSEMAPHORE ***
app:10492024-03-20 07:08:10.601 PMdebug*** EXIT MYSEMAPHORE ***
app:10492024-03-20 07:08:09.694 PMdebugBEFORE synchronized()
app:10492024-03-20 07:08:09.642 PMdebugBEFORE synchronized()
app:10492024-03-20 07:08:09.598 PMdebugTest1
app:10492024-03-20 07:08:09.595 PMdebug*** ENTER MYSEMAPHORE ***
app:10492024-03-20 07:08:09.592 PMdebugBEFORE synchronized()
app:10492024-03-20 07:08:09.362 PMdebugupdated(1)
app:10492024-03-20 07:08:09.359 PMdebuginstalled()
The first run (between updated(1) and updated(2)) is missing "Test0" output. the second run (above updated(2)) is correct and shows Test0 thru Test3. All runs after the first run are correct. The first run is no longer working. I also did the same test and used the sem object instead of using synchronized():
import java.util.concurrent.Semaphore
import groovy.transform.Field
@Field static Semaphore sem = new Semaphore(1)
@Field static RunNumber = 1
definition(
name: "SemaphoreTest2",
namespace: "Example",
author: "Hubitat Example",
description: "Test Semaphors",
category: "Convenience",
iconUrl: "",
iconX2Url: "",
singleThreaded: false)
def installed() {
log.debug "installed"
updated()
}
def updated() {
log.debug "updated(" + RunNumber + ")"
RunNumber++
trace()
}
def uninstalled() {
log.debug "uninstalled()"
}
def trace()
{
[0,1,2,3].each { runInMillis(0, "MySemaphore", [overwrite: false, data: "Test${it}"]) }
}
def MySemaphore(String Line) {
log.debug "BEFORE synchronized()"
// synchronized(this.MySemaphore) {
sem.acquire()
log.debug "*** ENTER MYSEMAPHORE ***"
log.debug Line
pauseExecution(1000) // pause for a second
log.debug "*** EXIT MYSEMAPHORE ***"
// }
sem.release()
}
And got similar results (This scenario was also missing Test1 along with Test0).
I ran these Apps in 2.3.8.128 and if you run them and it runs correctly please provide me your version number.
Thanks