thread does not work the way I thought it did in Odin
This commit is contained in:
24
http.odin
24
http.odin
@@ -204,14 +204,14 @@ server_start :: proc(server: ^Server) -> bool {
|
||||
conn_data.conn = conn
|
||||
conn_data.source = source
|
||||
|
||||
// Spawn a new thread for this connection
|
||||
t := thread.create(connection_worker_thread)
|
||||
if t != nil {
|
||||
//t.init_context = context // We dont actually need need to share the main threads context
|
||||
t.data = conn_data
|
||||
thread.start(t)
|
||||
} else {
|
||||
// Failed to create thread, close connection
|
||||
// Spawn with self_cleanup, thread resources are freed automatically on exit
|
||||
t := thread.create_and_start_with_data(
|
||||
conn_data,
|
||||
connection_worker,
|
||||
self_cleanup = true,
|
||||
)
|
||||
|
||||
if t == nil {
|
||||
net.close(conn)
|
||||
free(conn_data, server.allocator)
|
||||
}
|
||||
@@ -230,11 +230,9 @@ server_stop :: proc(server: ^Server) {
|
||||
}
|
||||
}
|
||||
|
||||
// Worker thread procedure
|
||||
connection_worker_thread :: proc(t: ^thread.Thread) {
|
||||
defer thread.destroy(t)
|
||||
|
||||
conn_data := cast(^Connection_Task_Data)t.data
|
||||
// Spawn connection worker with rawptr instead of a new thread
|
||||
connection_worker :: proc(data: rawptr) {
|
||||
conn_data := cast(^Connection_Task_Data)data
|
||||
defer free(conn_data, conn_data.server.allocator)
|
||||
|
||||
handle_connection(conn_data.server, conn_data.conn, conn_data.source)
|
||||
|
||||
Reference in New Issue
Block a user