On 7/24/17 9:11 AM, George Neuner wrote:
Hi David,
On 7/24/2017 8:18 AM, David Storrs wrote:
What happens in the following code?
(define dbh (postgresql-connect ...))
;; Use the DBH in a new thread
(thread (thunk
(while ...some long-running condition...
(sleep 1) ; don't flood the DB
(query-exec dbh "insert into users ..."))))
;; And in the main thread
(query-exec dbh ...)
I now have a database object that's being shared between two threads,
yes? Or is the object copied when the new thread is created and, if
so, what will that do to the underlying connection to the DB?
The single DBMS connection is being shared by the 2 threads. That's a
recipe for disaster if both try to use it simultaneously.
To clarify "disaster": Connections are thread-safe, so the queries
performed by the 2 threads will be interleaved in some order, which is
fine if both threads are just doing reads. But the threads are not
isolated ("session-safe" or "conversation-safe"?). For example, if one
thread changes the time zone, it affects queries made by the other
thread. If one thread starts and later rolls back a transaction, it
might undo modifications made by the other thread. And so on.
Ryan
--
You received this message because you are subscribed to the Google Groups "Racket
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.