Coder Social home page Coder Social logo

Comments (8)

beef9999 avatar beef9999 commented on May 8, 2024 1

OK, please feel free to ask if you have any questions.

We also have a Slack chatroom for people who want instant replies and talks, you can send me emails to book time and see if any of our team members are online to serve at that time

from photonlibos.

beef9999 avatar beef9999 commented on May 8, 2024 1

https://join.slack.com/t/photonlibos/shared_invite/zt-1wcmopjw0-wsNZxNtv6teJQxBzm_jKag

Yes you will need a temporary struct, the current create11 implementation basically does a placement-new operation ,

new (p) Pair{std::forward<F>(f), SavedArgs{std::forward<ARGUMENTS>(args)...}};

Thread create has some cost, to minimize it, you can use ThreadPool

By the way, context switch will not happen inside the thread create function call , that means the sub thread (callee) only got its stack allocated. After the caller went to sleep(yield), the sub thread callee will have a chance to run

from photonlibos.

beef9999 avatar beef9999 commented on May 8, 2024

photon::thread_create11() is the C++11 implementation in thread/thread11.h.

We also have a photon::thread* photon::thread_create(thread_entry start, void* arg) in thread/thread.h

BTW, what kind of project do you plan to use this c wrapper in?

from photonlibos.

lihuiba avatar lihuiba commented on May 8, 2024

So how can we call it from C?

photon::thread_create is a c-style function that creates a photon thread. This may fits better for your needs.

accepts a void* instead of F can be added?

I suppose this void* is actually a function pointer? You can pass the function pointer (of proper type) directly to photon::thread_create.

from photonlibos.

lihuiba avatar lihuiba commented on May 8, 2024

what kind of project

Probably langv (https://github.com/vlang/v).

I've never heard of it before, but it looks like a great language (according to the feature-list).

from photonlibos.

medvednikov avatar medvednikov commented on May 8, 2024

Thanks @beef9999 !

Yes, I want to use it internally for V's coroutines/scheduler.

from photonlibos.

medvednikov avatar medvednikov commented on May 8, 2024

Thanks, that's great.

What's the Slack link?

I managed to set it up using thread_create(). In the C++11 version it's easy to just list all arguments that need to be passed. In thread_create() there's only one argument. Do I need to use temporary structs to pass multiple arguments, or is there a way to do so like with thread_create11()?

from photonlibos.

lihuiba avatar lihuiba commented on May 8, 2024

is there a way to do so like with thread_create11()?

thread_create11 uses template meta-programming to realize a generic temp struct in order to pass arbitrary number (and types) of arguments. But it is not accessible from C. You have to do it manually in C.

When invoking thread_create(), you have an option to reserved some space in the new stack for the temp struct, so as to avoid an extra allocation for it. The placement new operation mentioned by @beef9999 uses this trick.

from photonlibos.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.