[SPDK] 答复: Re: thread->msg_cache is not safe when multiple threads send messages to same spdk_th read

Sunshihao (Euler OS) <sunshihao at huawei.com>
Newsgroups dev.linux.lists.spdk
Message-ID <[email protected]>
Dear maintainer Jim, thank you for your reply.

After reading your email, I know I have used the wrong way to submiting io.

When I create a thread to submit io, I don't create spdk_thread structure for the thread, this structure only be created in spdk_reactors_start api for every lcore;
Must I create spdk_thread structure for every submit thread?


Please give me some advice, thank you!


-----邮件原件-----
发件人: Harris, James R [mailto:james.r.harris(a)intel.com] 
发送时间: 2020年9月16日 3:32
收件人: Storage Performance Development Kit <spdk(a)lists.01.org>
主题: [SPDK] Re: thread->msg_cache is not safe when multiple threads send messages to same spdk_thread

Hi,

local_thread gets its value from _get_thread().  _get_thread() returns the thread-local spdk_thread structure for the calling thread. So if multiple threads call spdk_thread_send_msg() in parallel, they will each use their own thread-local spdk_thread structure and no lock or synchronization is needed.

-Jim

On 9/15/20, 6:33 AM, "sunshihao(a)huawei.com" <sunshihao(a)huawei.com> wrote:

    hello,maintainer:
    when i use spdk api spdk_thread_send_msg to send io read/write msg,i found a bug:
    multiple threads send msg to one spdk_thread,they may get msg form local_thread->msg_cache,there is not a lock or cas to 
    ensure the safety of the linked list。 

             msg = NULL;

    	if (local_thread != NULL) {
    		if (local_thread->msg_cache_count > 0) {
    				msg = SLIST_FIRST(&local_thread->msg_cache);    /* here maybe not thread safe */
    				assert(msg != NULL);
    				SLIST_REMOVE_HEAD(&local_thread->msg_cache, link);
    				local_thread->msg_cache_count--;
    		}
    	}

    i don't konw whether is my wrong way to use spdk_thread_send_msg  or the list is not safe,so please give me some advice。
    Thank you!
    _______________________________________________
    SPDK mailing list -- spdk(a)lists.01.org
    To unsubscribe send an email to spdk-leave(a)lists.01.org

_______________________________________________
SPDK mailing list -- spdk(a)lists.01.org
To unsubscribe send an email to spdk-leave(a)lists.01.org
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.