Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multithread issues #52

Closed
Frassle opened this issue May 5, 2014 · 4 comments
Closed

Multithread issues #52

Frassle opened this issue May 5, 2014 · 4 comments

Comments

@Frassle
Copy link
Contributor

Frassle commented May 5, 2014

Currently I'm running into issues where if I have one shared context or a context per method I'm hitting exceptional code paths (mostly trying to add things to dictionaries with a key that already exists). I'm happy to try and help fix this but I want to know what the expected behavior should be. Should you be able to use one context in multiple threads safely, or should you create a new context per thread or should you create a new context per thread but create the context while holding onto a lock for the type provider.
A) Context is thread safe:

// in thread 1
query { for row in ctx.table1 do select row }
// in thread 2
query { for row in ctx.table2 do select row }

B) Context creation is thread safe:

// in thread 1
let ctx = sql.GetDataContext()
query { for row in ctx.table1 do select row }
// in thread 2
let ctx = sql.GetDataContext()
query { for row in ctx.table2 do select row }

C) No thread safety

// in thread 1
let ctx = lock sql (fun () -> sql.GetDataContext())
query { for row in ctx.table1 do select row }
// in thread 2
let ctx = lock sql (fun () -> sql.GetDataContext())
query { for row in ctx.table2 do select row }
@pezipink
Copy link
Contributor

pezipink commented May 5, 2014

I think we can probably fix most of these issues by making the various dictionaries into concurrent ones. It seems best to aim for being able to share a context with multiple threads. (May even be able to look at making the dictionaries static as well)

This is something on my to do list but I haven't got around to it yet. When I come to doing CRUD (soon) I will have to be a bit more careful, but for now the concurrent dictionaries should do the trick. Perhaps you could try it just in the MySQL one and see how we get on? Let me know of any other threaded problems you are having as well.

Cheers, Ross

Frassle pushed a commit to Frassle/SQLProvider that referenced this issue May 6, 2014
In relation to issue fsprojects#52. Adding locks to the GetColumn calls that are
used to preload the columns seems to solve the immediate thread safety
issues I was hitting.
@Frassle
Copy link
Contributor Author

Frassle commented May 6, 2014

Well even simpler, I added locks around provider creating and the calls to GetColumns that were preloading the column data. Seems to of solved the immediate issue.

Frassle pushed a commit to Frassle/SQLProvider that referenced this issue May 6, 2014
In relation to issue fsprojects#52. Adding locks to the GetColumn calls that are
used to preload the columns seems to solve the immediate thread safety
issues I was hitting.
Frassle pushed a commit to Frassle/SQLProvider that referenced this issue May 7, 2014
In relation to issue fsprojects#52. Adding locks to the GetColumn calls that are
used to preload the columns seems to solve the immediate thread safety
issues I was hitting.
Frassle added a commit to Frassle/SQLProvider that referenced this issue May 9, 2014
In relation to issue fsprojects#52. Adding locks to the GetColumn calls that are
used to preload the columns seems to solve the immediate thread safety
issues I was hitting.
@Frassle
Copy link
Contributor Author

Frassle commented May 20, 2014

I've removed my locks workaround and updated to the latest SQLProvider (with CRUD support) and have not seen any thread issues yet. It's probably ok to close this.

@pezipink
Copy link
Contributor

I re-implemented your locks with the new architecture, however there are likely going to be be threading issues with the initial CRUD stuff so I am leaving this open for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants