I'm far from a Lua expert but my understanding of the "Lua way" of doing things is to use coroutines (lua threads). Each coroutine will have their own stack but share global data.
Thus you can have much fewer PB-threads, e.g. 1000 lua threads and 10 PB threads = 10 000 lua threads
With fewer PB ...
Search found 90 matches
- Mon Oct 13, 2025 2:46 pm
- Forum: Coding Questions
- Topic: How to avoid race conditions and state/stack pollution when creating multiple lua_State in PureBasic with Lua 5.3?
- Replies: 2
- Views: 626
- Mon Oct 13, 2025 2:18 pm
- Forum: Coding Questions
- Topic: How to avoid race conditions and state/stack pollution when creating multiple lua_State in PureBasic with Lua 5.3?
- Replies: 2
- Views: 626
Re: How to avoid race conditions and state/stack pollution when creating multiple lua_State in PureBasic with Lua 5.3?
You can use atomic operations for writing to variables from multiple threads without using a mutex.
https://learn.microsoft.com/en-us/windo ... ble-access
https://learn.microsoft.com/en-us/windo ... ble-access
- Wed Oct 01, 2025 4:43 pm
- Forum: Bugs - Windows
- Topic: [Done] PureUnit triggers GUI alert on fail
- Replies: 4
- Views: 776
Re: PureUnit triggers GUI alert on fail
As we have 2 version, it makes sense than the console version would be without GUI. That said, you can use the '-q' flag (quiet) which should solve your requester issue.
Sorry for forgetting to mention, the q quiet flag doesn't work in this case. Already tested that.
"%ProgramFiles%\PureBasic ...
- Wed Oct 01, 2025 12:45 pm
- Forum: Bugs - Windows
- Topic: [Done] PureUnit triggers GUI alert on fail
- Replies: 4
- Views: 776
[Done] PureUnit triggers GUI alert on fail
Calling Assert() with a falsy expression or Fail() inside a module triggers a GUI alert (MessageRequester) when calling PureUnit.exe from the command line.
Test case
test.pbi
Procedure MyProcedure()
Assert(#False)
EndProcedure
DeclareModule MyModule
Declare MyProcedure()
EndDeclareModule ...
Test case
test.pbi
Procedure MyProcedure()
Assert(#False)
EndProcedure
DeclareModule MyModule
Declare MyProcedure()
EndDeclareModule ...
- Wed Jul 16, 2025 7:41 pm
- Forum: Coding Questions
- Topic: using semaphores in threads and TrySemaphore(Semaphore)
- Replies: 13
- Views: 1144
Re: using semaphores in threads and TrySemaphore(Semaphore)
For completeness, without the overengineering
EnableExplicit
Enumeration
#WINDOW
#TEXT
EndEnumeration
Enumeration #PB_Event_FirstCustomValue
#MESSAGE
EndEnumeration
Procedure AddMessagesThread(*notused)
Protected i, *buffer.String
Repeat
Delay(100)
i + 1
*buffer = AllocateStructure ...
EnableExplicit
Enumeration
#WINDOW
#TEXT
EndEnumeration
Enumeration #PB_Event_FirstCustomValue
#MESSAGE
EndEnumeration
Procedure AddMessagesThread(*notused)
Protected i, *buffer.String
Repeat
Delay(100)
i + 1
*buffer = AllocateStructure ...
- Wed Jul 16, 2025 7:27 pm
- Forum: Coding Questions
- Topic: using semaphores in threads and TrySemaphore(Semaphore)
- Replies: 13
- Views: 1144
Re: using semaphores in threads and TrySemaphore(Semaphore)
For your second example you need no lists and no Mutex.
In the thread allocate a buffer, poke a string into it and send it by PostEvent() to the window queue.
In the window queue pick the buffer, peek the string and free the memory.
Nothing can collide here
Correct. I just wanted to avoid ...
- Wed Jul 16, 2025 1:40 pm
- Forum: Coding Questions
- Topic: using semaphores in threads and TrySemaphore(Semaphore)
- Replies: 13
- Views: 1144
Re: using semaphores in threads and TrySemaphore(Semaphore)
Here is another example where we instead of using a semaphore we use PostEvent() to send an event
EnableExplicit
Global NewList messages.s()
Global mutex
Enumeration
#WINDOW
#TEXT
EndEnumeration
Enumeration #PB_Event_FirstCustomValue
#MESSAGE
EndEnumeration
Procedure AddMessagesThread ...
EnableExplicit
Global NewList messages.s()
Global mutex
Enumeration
#WINDOW
#TEXT
EndEnumeration
Enumeration #PB_Event_FirstCustomValue
#MESSAGE
EndEnumeration
Procedure AddMessagesThread ...
- Wed Jul 16, 2025 12:59 pm
- Forum: Coding Questions
- Topic: using semaphores in threads and TrySemaphore(Semaphore)
- Replies: 13
- Views: 1144
Re: using semaphores in threads and TrySemaphore(Semaphore)
Here is an example of using TrySemaphore() within the main event loop that we don't want to block
EnableExplicit
Global NewList messages.s()
Global mutex
Global semaphore
Enumeration
#WINDOW
#TEXT
EndEnumeration
Procedure AddMessagesThread(*notused)
Protected i
Repeat
Delay(1000)
i + 1 ...
EnableExplicit
Global NewList messages.s()
Global mutex
Global semaphore
Enumeration
#WINDOW
#TEXT
EndEnumeration
Procedure AddMessagesThread(*notused)
Protected i
Repeat
Delay(1000)
i + 1 ...
- Mon May 12, 2025 10:33 am
- Forum: Coding Questions
- Topic: Exporting procedures when compiling against static library
- Replies: 1
- Views: 598
Re: Exporting procedures when compiling against static library
I managed to get it working for the original ASM backend by adding this line.
!public _Procedure0 as 'multiplier'
I figured this out by digging around in the forum and looking at the asm output.
To my limited understanding, by exporting multiplier with ProcedureDLL we get a symbol called ...
!public _Procedure0 as 'multiplier'
I figured this out by digging around in the forum and looking at the asm output.
To my limited understanding, by exporting multiplier with ProcedureDLL we get a symbol called ...
- Sun May 11, 2025 1:54 pm
- Forum: Coding Questions
- Topic: Exporting procedures when compiling against static library
- Replies: 1
- Views: 598
Exporting procedures when compiling against static library
I wonder if this is possible with PureBasic, the idea is that create a static library in another language and to compile that with PureBasic to a binary and avoid any extra dynamic dll files. The static library exports functions that PureBasic imports but the static library also imports procedures ...
- Mon Feb 03, 2025 4:16 pm
- Forum: Coding Questions
- Topic: #PB_Any object result values after PB 6.20
- Replies: 17
- Views: 5134
Re: #PB_Any object result values after PB 6.20
What does an administrative user do with these ids? The administrative user cannot really share these with anyone, like over the phone, because they are local to his running instance.
Thus one solution is to remap these numbers with your own Map where you can use any sequence you like as long as ...
Thus one solution is to remap these numbers with your own Map where you can use any sequence you like as long as ...
- Wed Dec 25, 2024 1:35 pm
- Forum: Off Topic
- Topic: Happy Christmas
- Replies: 17
- Views: 10322
Re: Happy Christmas
God Jul from Sweden!
- Tue Nov 12, 2024 2:58 pm
- Forum: Off Topic
- Topic: SQLite open database question
- Replies: 16
- Views: 6457
Re: SQLite open database question
About your database schema, do you store any large blobs together with other columns? If you do consider either store on blob directly on disk or have blobs in separate table. This helps performance when querying and updating tables by moving blobs to separate table.
Check you indexes, typically a ...
Check you indexes, typically a ...
- Tue Nov 12, 2024 2:38 pm
- Forum: Off Topic
- Topic: SQLite open database question
- Replies: 16
- Views: 6457
Re: SQLite open database question
Greetings
https://sqlite.org/whentouse.html
Client/Server Applications
If there are many client programs sending SQL to the same database over a network, then use a client/server database engine instead of SQLite. SQLite will work over a network filesystem, but because of the latency ...
https://sqlite.org/whentouse.html
Client/Server Applications
If there are many client programs sending SQL to the same database over a network, then use a client/server database engine instead of SQLite. SQLite will work over a network filesystem, but because of the latency ...
- Mon Oct 14, 2024 1:53 pm
- Forum: Coding Questions
- Topic: FreeStructure() crash
- Replies: 39
- Views: 5757
Re: FreeStructure() crash
Antivirus software? Faulty RAM memory sticks?